mirror of https://github.com/acidanthera/audk.git
Core/Dxe: Changed line ending to Windows style.
This commit is contained in:
parent
5b59ec5e07
commit
d8aa9c3ea7
|
@ -70,21 +70,21 @@
|
|||
SysCall/SupportedProtocols.h
|
||||
SysCall/SupportedProtocols.c
|
||||
|
||||
[Sources.IA32]
|
||||
SysCall/IA32/InitializeMsr.c
|
||||
SysCall/IA32/CoreBootServices.nasm
|
||||
[Sources.IA32]
|
||||
SysCall/IA32/InitializeMsr.c
|
||||
SysCall/IA32/CoreBootServices.nasm
|
||||
|
||||
[Sources.X64]
|
||||
SysCall/X64/InitializeMsr.c
|
||||
SysCall/X64/CoreBootServices.nasm
|
||||
[Sources.X64]
|
||||
SysCall/X64/InitializeMsr.c
|
||||
SysCall/X64/CoreBootServices.nasm
|
||||
|
||||
[Sources.ARM]
|
||||
SysCall/ARM/InitializeMsr.c
|
||||
SysCall/ARM/CoreBootServices.S
|
||||
|
||||
[Sources.AARCH64]
|
||||
SysCall/AARCH64/InitializeMsr.c
|
||||
SysCall/AARCH64/CoreBootServices.S
|
||||
[Sources.ARM]
|
||||
SysCall/ARM/InitializeMsr.c
|
||||
SysCall/ARM/CoreBootServices.S
|
||||
|
||||
[Sources.AARCH64]
|
||||
SysCall/AARCH64/InitializeMsr.c
|
||||
SysCall/AARCH64/CoreBootServices.S
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
|
@ -93,7 +93,7 @@
|
|||
OvmfPkg/OvmfPkg.dec
|
||||
ArmPkg/ArmPkg.dec
|
||||
ArmVirtPkg/ArmVirtPkg.dec
|
||||
|
||||
|
||||
[LibraryClasses]
|
||||
BaseMemoryLib
|
||||
CacheMaintenanceLib
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <AsmMacroIoLibV8.h>
|
||||
|
||||
.extern ASM_PFX(Ring3Call)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// SysCall (
|
||||
// IN UINT8 Type,
|
||||
// ...
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(SysCall)
|
||||
svc #0
|
||||
ret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// Ring3EntryPoint (
|
||||
// IN RING3_CALL_DATA *Data
|
||||
// );
|
||||
//
|
||||
// (x0) Data
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(Ring3EntryPoint)
|
||||
b ASM_PFX(Ring3Call)
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <AsmMacroIoLibV8.h>
|
||||
|
||||
.extern ASM_PFX(Ring3Call)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// SysCall (
|
||||
// IN UINT8 Type,
|
||||
// ...
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(SysCall)
|
||||
svc #0
|
||||
ret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// Ring3EntryPoint (
|
||||
// IN RING3_CALL_DATA *Data
|
||||
// );
|
||||
//
|
||||
// (x0) Data
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(Ring3EntryPoint)
|
||||
b ASM_PFX(Ring3Call)
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <AsmMacroIoLib.h>
|
||||
|
||||
.extern ASM_PFX(Ring3Call)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// SysCall (
|
||||
// IN UINT8 Type,
|
||||
// ...
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(SysCall)
|
||||
svc #0
|
||||
bx LR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// Ring3EntryPoint (
|
||||
// IN RING3_CALL_DATA *Data
|
||||
// );
|
||||
//
|
||||
// (r0) Data
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(Ring3EntryPoint)
|
||||
b ASM_PFX(Ring3Call)
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <AsmMacroIoLib.h>
|
||||
|
||||
.extern ASM_PFX(Ring3Call)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// SysCall (
|
||||
// IN UINT8 Type,
|
||||
// ...
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(SysCall)
|
||||
svc #0
|
||||
bx LR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// Ring3EntryPoint (
|
||||
// IN RING3_CALL_DATA *Data
|
||||
// );
|
||||
//
|
||||
// (r0) Data
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(Ring3EntryPoint)
|
||||
b ASM_PFX(Ring3Call)
|
||||
|
|
|
@ -1,265 +1,265 @@
|
|||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/MemoryPoolLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
|
||||
#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)CoreAllocatePool, // AllocatePool
|
||||
(EFI_FREE_POOL)CoreFreePool, // 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_RUNTIME_SERVICES mRuntimeServices = {
|
||||
{
|
||||
EFI_RUNTIME_SERVICES_SIGNATURE, // Signature
|
||||
EFI_RUNTIME_SERVICES_REVISION, // Revision
|
||||
sizeof (EFI_RUNTIME_SERVICES), // HeaderSize
|
||||
0, // CRC32
|
||||
0 // Reserved
|
||||
},
|
||||
(EFI_GET_TIME)Ring3GetTime, // GetTime
|
||||
(EFI_SET_TIME)Ring3SetTime, // SetTime
|
||||
(EFI_GET_WAKEUP_TIME)Ring3GetWakeupTime, // GetWakeupTime
|
||||
(EFI_SET_WAKEUP_TIME)Ring3SetWakeupTime, // SetWakeupTime
|
||||
(EFI_SET_VIRTUAL_ADDRESS_MAP)Ring3SetVirtualAddressMap, // SetVirtualAddressMap
|
||||
(EFI_CONVERT_POINTER)Ring3ConvertPointer, // ConvertPointer
|
||||
(EFI_GET_VARIABLE)Ring3GetVariable, // GetVariable
|
||||
(EFI_GET_NEXT_VARIABLE_NAME)Ring3GetNextVariableName, // GetNextVariableName
|
||||
(EFI_SET_VARIABLE)Ring3SetVariable, // SetVariable
|
||||
(EFI_GET_NEXT_HIGH_MONO_COUNT)Ring3GetNextHighMonotonicCount, // GetNextHighMonotonicCount
|
||||
(EFI_RESET_SYSTEM)Ring3ResetSystem, // ResetSystem
|
||||
(EFI_UPDATE_CAPSULE)Ring3UpdateCapsule, // UpdateCapsule
|
||||
(EFI_QUERY_CAPSULE_CAPABILITIES)Ring3QueryCapsuleCapabilities, // QueryCapsuleCapabilities
|
||||
(EFI_QUERY_VARIABLE_INFO)Ring3QueryVariableInfo // QueryVariableInfo
|
||||
};
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3EntryPoint (
|
||||
IN RING3_CALL_DATA *Data
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_0)(
|
||||
VOID
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_1)(
|
||||
IN UINTN Argument1
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_2)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_3)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_4)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_5)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4,
|
||||
IN UINTN Argument5
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_6)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4,
|
||||
IN UINTN Argument5,
|
||||
IN UINTN Argument6
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_7)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4,
|
||||
IN UINTN Argument5,
|
||||
IN UINTN Argument6,
|
||||
IN UINTN Argument7
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_8)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4,
|
||||
IN UINTN Argument5,
|
||||
IN UINTN Argument6,
|
||||
IN UINTN Argument7,
|
||||
IN UINTN Argument8
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3Call (
|
||||
IN RING3_CALL_DATA *Data
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
FUNCTION_0 Function0;
|
||||
FUNCTION_1 Function1;
|
||||
FUNCTION_2 Function2;
|
||||
FUNCTION_3 Function3;
|
||||
FUNCTION_4 Function4;
|
||||
FUNCTION_5 Function5;
|
||||
FUNCTION_6 Function6;
|
||||
FUNCTION_7 Function7;
|
||||
FUNCTION_8 Function8;
|
||||
|
||||
switch (Data->NumberOfArguments) {
|
||||
case 0:
|
||||
Function0 = (FUNCTION_0)Data->EntryPoint;
|
||||
Status = Function0 ();
|
||||
break;
|
||||
case 1:
|
||||
Function1 = (FUNCTION_1)Data->EntryPoint;
|
||||
Status = Function1 (Data->Arguments[0]);
|
||||
break;
|
||||
case 2:
|
||||
Function2 = (FUNCTION_2)Data->EntryPoint;
|
||||
Status = Function2 (Data->Arguments[0], Data->Arguments[1]);
|
||||
break;
|
||||
case 3:
|
||||
Function3 = (FUNCTION_3)Data->EntryPoint;
|
||||
Status = Function3 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2]);
|
||||
break;
|
||||
case 4:
|
||||
Function4 = (FUNCTION_4)Data->EntryPoint;
|
||||
Status = Function4 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3]);
|
||||
break;
|
||||
case 5:
|
||||
Function5 = (FUNCTION_5)Data->EntryPoint;
|
||||
Status = Function5 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4]);
|
||||
break;
|
||||
case 6:
|
||||
Function6 = (FUNCTION_6)Data->EntryPoint;
|
||||
Status = Function6 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4], Data->Arguments[5]);
|
||||
break;
|
||||
case 7:
|
||||
Function7 = (FUNCTION_7)Data->EntryPoint;
|
||||
Status = Function7 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4], Data->Arguments[5], Data->Arguments[6]);
|
||||
break;
|
||||
case 8:
|
||||
Function8 = (FUNCTION_8)Data->EntryPoint;
|
||||
Status = Function8 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4], Data->Arguments[5], Data->Arguments[6], Data->Arguments[7]);
|
||||
break;
|
||||
default:
|
||||
Status = EFI_UNSUPPORTED;
|
||||
break;
|
||||
}
|
||||
|
||||
SysCall (SysCallReturnToCore, Status);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3Initialization (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
RING3_DATA *Ring3Data;
|
||||
|
||||
Ring3Data = (RING3_DATA *)SystemTable;
|
||||
|
||||
Ring3Data->EntryPoint = (VOID *)Ring3EntryPoint;
|
||||
Ring3Data->BootServices = &mBootServices;
|
||||
Ring3Data->RuntimeServices = &mRuntimeServices;
|
||||
|
||||
gBS = &mBootServices;
|
||||
gRT = &mRuntimeServices;
|
||||
|
||||
CoreInitializePool ();
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/MemoryPoolLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
|
||||
#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)CoreAllocatePool, // AllocatePool
|
||||
(EFI_FREE_POOL)CoreFreePool, // 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_RUNTIME_SERVICES mRuntimeServices = {
|
||||
{
|
||||
EFI_RUNTIME_SERVICES_SIGNATURE, // Signature
|
||||
EFI_RUNTIME_SERVICES_REVISION, // Revision
|
||||
sizeof (EFI_RUNTIME_SERVICES), // HeaderSize
|
||||
0, // CRC32
|
||||
0 // Reserved
|
||||
},
|
||||
(EFI_GET_TIME)Ring3GetTime, // GetTime
|
||||
(EFI_SET_TIME)Ring3SetTime, // SetTime
|
||||
(EFI_GET_WAKEUP_TIME)Ring3GetWakeupTime, // GetWakeupTime
|
||||
(EFI_SET_WAKEUP_TIME)Ring3SetWakeupTime, // SetWakeupTime
|
||||
(EFI_SET_VIRTUAL_ADDRESS_MAP)Ring3SetVirtualAddressMap, // SetVirtualAddressMap
|
||||
(EFI_CONVERT_POINTER)Ring3ConvertPointer, // ConvertPointer
|
||||
(EFI_GET_VARIABLE)Ring3GetVariable, // GetVariable
|
||||
(EFI_GET_NEXT_VARIABLE_NAME)Ring3GetNextVariableName, // GetNextVariableName
|
||||
(EFI_SET_VARIABLE)Ring3SetVariable, // SetVariable
|
||||
(EFI_GET_NEXT_HIGH_MONO_COUNT)Ring3GetNextHighMonotonicCount, // GetNextHighMonotonicCount
|
||||
(EFI_RESET_SYSTEM)Ring3ResetSystem, // ResetSystem
|
||||
(EFI_UPDATE_CAPSULE)Ring3UpdateCapsule, // UpdateCapsule
|
||||
(EFI_QUERY_CAPSULE_CAPABILITIES)Ring3QueryCapsuleCapabilities, // QueryCapsuleCapabilities
|
||||
(EFI_QUERY_VARIABLE_INFO)Ring3QueryVariableInfo // QueryVariableInfo
|
||||
};
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3EntryPoint (
|
||||
IN RING3_CALL_DATA *Data
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_0)(
|
||||
VOID
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_1)(
|
||||
IN UINTN Argument1
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_2)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_3)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_4)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_5)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4,
|
||||
IN UINTN Argument5
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_6)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4,
|
||||
IN UINTN Argument5,
|
||||
IN UINTN Argument6
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_7)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4,
|
||||
IN UINTN Argument5,
|
||||
IN UINTN Argument6,
|
||||
IN UINTN Argument7
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *FUNCTION_8)(
|
||||
IN UINTN Argument1,
|
||||
IN UINTN Argument2,
|
||||
IN UINTN Argument3,
|
||||
IN UINTN Argument4,
|
||||
IN UINTN Argument5,
|
||||
IN UINTN Argument6,
|
||||
IN UINTN Argument7,
|
||||
IN UINTN Argument8
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3Call (
|
||||
IN RING3_CALL_DATA *Data
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
FUNCTION_0 Function0;
|
||||
FUNCTION_1 Function1;
|
||||
FUNCTION_2 Function2;
|
||||
FUNCTION_3 Function3;
|
||||
FUNCTION_4 Function4;
|
||||
FUNCTION_5 Function5;
|
||||
FUNCTION_6 Function6;
|
||||
FUNCTION_7 Function7;
|
||||
FUNCTION_8 Function8;
|
||||
|
||||
switch (Data->NumberOfArguments) {
|
||||
case 0:
|
||||
Function0 = (FUNCTION_0)Data->EntryPoint;
|
||||
Status = Function0 ();
|
||||
break;
|
||||
case 1:
|
||||
Function1 = (FUNCTION_1)Data->EntryPoint;
|
||||
Status = Function1 (Data->Arguments[0]);
|
||||
break;
|
||||
case 2:
|
||||
Function2 = (FUNCTION_2)Data->EntryPoint;
|
||||
Status = Function2 (Data->Arguments[0], Data->Arguments[1]);
|
||||
break;
|
||||
case 3:
|
||||
Function3 = (FUNCTION_3)Data->EntryPoint;
|
||||
Status = Function3 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2]);
|
||||
break;
|
||||
case 4:
|
||||
Function4 = (FUNCTION_4)Data->EntryPoint;
|
||||
Status = Function4 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3]);
|
||||
break;
|
||||
case 5:
|
||||
Function5 = (FUNCTION_5)Data->EntryPoint;
|
||||
Status = Function5 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4]);
|
||||
break;
|
||||
case 6:
|
||||
Function6 = (FUNCTION_6)Data->EntryPoint;
|
||||
Status = Function6 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4], Data->Arguments[5]);
|
||||
break;
|
||||
case 7:
|
||||
Function7 = (FUNCTION_7)Data->EntryPoint;
|
||||
Status = Function7 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4], Data->Arguments[5], Data->Arguments[6]);
|
||||
break;
|
||||
case 8:
|
||||
Function8 = (FUNCTION_8)Data->EntryPoint;
|
||||
Status = Function8 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4], Data->Arguments[5], Data->Arguments[6], Data->Arguments[7]);
|
||||
break;
|
||||
default:
|
||||
Status = EFI_UNSUPPORTED;
|
||||
break;
|
||||
}
|
||||
|
||||
SysCall (SysCallReturnToCore, Status);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3Initialization (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
RING3_DATA *Ring3Data;
|
||||
|
||||
Ring3Data = (RING3_DATA *)SystemTable;
|
||||
|
||||
Ring3Data->EntryPoint = (VOID *)Ring3EntryPoint;
|
||||
Ring3Data->BootServices = &mBootServices;
|
||||
Ring3Data->RuntimeServices = &mRuntimeServices;
|
||||
|
||||
gBS = &mBootServices;
|
||||
gRT = &mRuntimeServices;
|
||||
|
||||
CoreInitializePool ();
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -1,66 +1,66 @@
|
|||
## @file
|
||||
#
|
||||
# Ring3 driver for SysCalls.
|
||||
#
|
||||
# Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = DxeRing3
|
||||
FILE_GUID = 88EA50C2-0DEA-4F13-B691-B506554E632B
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
ENTRY_POINT = Ring3Initialization
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
|
||||
#
|
||||
|
||||
[Sources]
|
||||
Ring3.h
|
||||
DxeRing3.c
|
||||
Ring3UefiBootServices.c
|
||||
Ring3UefiRuntimeServices.c
|
||||
Ring3Protocols.c
|
||||
|
||||
[Sources.IA32]
|
||||
IA32/SysCall.nasm
|
||||
|
||||
[Sources.X64]
|
||||
X64/SysCall.nasm
|
||||
|
||||
[Sources.ARM]
|
||||
ARM/SysCall.S
|
||||
|
||||
[Sources.AARCH64]
|
||||
AARCH64/SysCall.S
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
ArmPkg/ArmPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
MemoryPoolLib
|
||||
UefiBootServicesTableLib
|
||||
UefiDriverEntryPoint
|
||||
UefiRuntimeServicesTableLib
|
||||
|
||||
[Protocols]
|
||||
gEfiDevicePathUtilitiesProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiDiskIoProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiUnicodeCollationProtocolGuid ## SOMETIMES_CONSUMES
|
||||
|
||||
[Depex]
|
||||
TRUE
|
||||
## @file
|
||||
#
|
||||
# Ring3 driver for SysCalls.
|
||||
#
|
||||
# Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = DxeRing3
|
||||
FILE_GUID = 88EA50C2-0DEA-4F13-B691-B506554E632B
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
ENTRY_POINT = Ring3Initialization
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
|
||||
#
|
||||
|
||||
[Sources]
|
||||
Ring3.h
|
||||
DxeRing3.c
|
||||
Ring3UefiBootServices.c
|
||||
Ring3UefiRuntimeServices.c
|
||||
Ring3Protocols.c
|
||||
|
||||
[Sources.IA32]
|
||||
IA32/SysCall.nasm
|
||||
|
||||
[Sources.X64]
|
||||
X64/SysCall.nasm
|
||||
|
||||
[Sources.ARM]
|
||||
ARM/SysCall.S
|
||||
|
||||
[Sources.AARCH64]
|
||||
AARCH64/SysCall.S
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
ArmPkg/ArmPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
MemoryPoolLib
|
||||
UefiBootServicesTableLib
|
||||
UefiDriverEntryPoint
|
||||
UefiRuntimeServicesTableLib
|
||||
|
||||
[Protocols]
|
||||
gEfiDevicePathUtilitiesProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiDiskIoProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gEfiUnicodeCollationProtocolGuid ## SOMETIMES_CONSUMES
|
||||
|
||||
[Depex]
|
||||
TRUE
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
;------------------------------------------------------------------------------
|
||||
; Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
extern ASM_PFX(Ring3Call)
|
||||
|
||||
DEFAULT REL
|
||||
SECTION .text
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; SysCall (
|
||||
; IN UINT8 Type,
|
||||
; ...
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(SysCall)
|
||||
ASM_PFX(SysCall):
|
||||
mov edx, esp
|
||||
mov ecx, [esp + 4] ; Type
|
||||
lea eax, [userReturnAddress]
|
||||
|
||||
sysenter
|
||||
userReturnAddress:
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; Ring3EntryPoint (
|
||||
; IN RING3_CALL_DATA *Data
|
||||
; );
|
||||
;
|
||||
; (eax) Data
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(Ring3EntryPoint)
|
||||
ASM_PFX(Ring3EntryPoint):
|
||||
push eax
|
||||
|
||||
call ASM_PFX(Ring3Call)
|
||||
;------------------------------------------------------------------------------
|
||||
; Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
extern ASM_PFX(Ring3Call)
|
||||
|
||||
DEFAULT REL
|
||||
SECTION .text
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; SysCall (
|
||||
; IN UINT8 Type,
|
||||
; ...
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(SysCall)
|
||||
ASM_PFX(SysCall):
|
||||
mov edx, esp
|
||||
mov ecx, [esp + 4] ; Type
|
||||
lea eax, [userReturnAddress]
|
||||
|
||||
sysenter
|
||||
userReturnAddress:
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; Ring3EntryPoint (
|
||||
; IN RING3_CALL_DATA *Data
|
||||
; );
|
||||
;
|
||||
; (eax) Data
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(Ring3EntryPoint)
|
||||
ASM_PFX(Ring3EntryPoint):
|
||||
push eax
|
||||
|
||||
call ASM_PFX(Ring3Call)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,210 +1,210 @@
|
|||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include "Ring3.h"
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3BlockIoReset (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallBlockIoReset,
|
||||
This,
|
||||
ExtendedVerification
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3BlockIoRead (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallBlockIoRead,
|
||||
This,
|
||||
MediaId,
|
||||
BufferSize,
|
||||
Buffer,
|
||||
Lba
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3BlockIoWrite (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallBlockIoWrite,
|
||||
This,
|
||||
MediaId,
|
||||
BufferSize,
|
||||
Buffer,
|
||||
Lba
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3BlockIoFlush (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallBlockIoFlush,
|
||||
This
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3DiskIoRead (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallDiskIoRead,
|
||||
This,
|
||||
MediaId,
|
||||
BufferSize,
|
||||
Buffer,
|
||||
Offset
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3DiskIoWrite (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallDiskIoWrite,
|
||||
This,
|
||||
MediaId,
|
||||
BufferSize,
|
||||
Buffer,
|
||||
Offset
|
||||
);
|
||||
}
|
||||
|
||||
INTN
|
||||
EFIAPI
|
||||
Ring3UnicodeStriColl (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN CHAR16 *Str1,
|
||||
IN CHAR16 *Str2
|
||||
)
|
||||
{
|
||||
return (INTN)SysCall (
|
||||
SysCallUnicodeStriColl,
|
||||
This,
|
||||
Str1,
|
||||
Str2
|
||||
);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Ring3UnicodeMetaiMatch (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN CHAR16 *String,
|
||||
IN CHAR16 *Pattern
|
||||
)
|
||||
{
|
||||
return (BOOLEAN)SysCall (
|
||||
SysCallUnicodeMetaiMatch,
|
||||
This,
|
||||
String,
|
||||
Pattern
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3UnicodeStrLwr (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN OUT CHAR16 *Str
|
||||
)
|
||||
{
|
||||
SysCall (
|
||||
SysCallUnicodeStrLwr,
|
||||
This,
|
||||
Str
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3UnicodeStrUpr (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN OUT CHAR16 *Str
|
||||
)
|
||||
{
|
||||
SysCall (
|
||||
SysCallUnicodeStrUpr,
|
||||
This,
|
||||
Str
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3UnicodeFatToStr (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN UINTN FatSize,
|
||||
IN CHAR8 *Fat,
|
||||
OUT CHAR16 *String
|
||||
)
|
||||
{
|
||||
SysCall (
|
||||
SysCallUnicodeFatToStr,
|
||||
This,
|
||||
FatSize,
|
||||
Fat,
|
||||
String
|
||||
);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Ring3UnicodeStrToFat (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN CHAR16 *String,
|
||||
IN UINTN FatSize,
|
||||
OUT CHAR8 *Fat
|
||||
)
|
||||
{
|
||||
return (BOOLEAN)SysCall (
|
||||
SysCallUnicodeStrToFat,
|
||||
This,
|
||||
String,
|
||||
FatSize,
|
||||
Fat
|
||||
);
|
||||
}
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include "Ring3.h"
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3BlockIoReset (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallBlockIoReset,
|
||||
This,
|
||||
ExtendedVerification
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3BlockIoRead (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallBlockIoRead,
|
||||
This,
|
||||
MediaId,
|
||||
BufferSize,
|
||||
Buffer,
|
||||
Lba
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3BlockIoWrite (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallBlockIoWrite,
|
||||
This,
|
||||
MediaId,
|
||||
BufferSize,
|
||||
Buffer,
|
||||
Lba
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3BlockIoFlush (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallBlockIoFlush,
|
||||
This
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3DiskIoRead (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallDiskIoRead,
|
||||
This,
|
||||
MediaId,
|
||||
BufferSize,
|
||||
Buffer,
|
||||
Offset
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3DiskIoWrite (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallDiskIoWrite,
|
||||
This,
|
||||
MediaId,
|
||||
BufferSize,
|
||||
Buffer,
|
||||
Offset
|
||||
);
|
||||
}
|
||||
|
||||
INTN
|
||||
EFIAPI
|
||||
Ring3UnicodeStriColl (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN CHAR16 *Str1,
|
||||
IN CHAR16 *Str2
|
||||
)
|
||||
{
|
||||
return (INTN)SysCall (
|
||||
SysCallUnicodeStriColl,
|
||||
This,
|
||||
Str1,
|
||||
Str2
|
||||
);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Ring3UnicodeMetaiMatch (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN CHAR16 *String,
|
||||
IN CHAR16 *Pattern
|
||||
)
|
||||
{
|
||||
return (BOOLEAN)SysCall (
|
||||
SysCallUnicodeMetaiMatch,
|
||||
This,
|
||||
String,
|
||||
Pattern
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3UnicodeStrLwr (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN OUT CHAR16 *Str
|
||||
)
|
||||
{
|
||||
SysCall (
|
||||
SysCallUnicodeStrLwr,
|
||||
This,
|
||||
Str
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3UnicodeStrUpr (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN OUT CHAR16 *Str
|
||||
)
|
||||
{
|
||||
SysCall (
|
||||
SysCallUnicodeStrUpr,
|
||||
This,
|
||||
Str
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3UnicodeFatToStr (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN UINTN FatSize,
|
||||
IN CHAR8 *Fat,
|
||||
OUT CHAR16 *String
|
||||
)
|
||||
{
|
||||
SysCall (
|
||||
SysCallUnicodeFatToStr,
|
||||
This,
|
||||
FatSize,
|
||||
Fat,
|
||||
String
|
||||
);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
Ring3UnicodeStrToFat (
|
||||
IN EFI_UNICODE_COLLATION_PROTOCOL *This,
|
||||
IN CHAR16 *String,
|
||||
IN UINTN FatSize,
|
||||
OUT CHAR8 *Fat
|
||||
)
|
||||
{
|
||||
return (BOOLEAN)SysCall (
|
||||
SysCallUnicodeStrToFat,
|
||||
This,
|
||||
String,
|
||||
FatSize,
|
||||
Fat
|
||||
);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,194 +1,194 @@
|
|||
#include <Uefi.h>
|
||||
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
|
||||
#include "Ring3.h"
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetTime (
|
||||
OUT EFI_TIME *Time,
|
||||
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: GetTime is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3SetTime (
|
||||
IN EFI_TIME *Time
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: SetTime is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetWakeupTime (
|
||||
OUT BOOLEAN *Enabled,
|
||||
OUT BOOLEAN *Pending,
|
||||
OUT EFI_TIME *Time
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: GetWakeupTime is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3SetWakeupTime (
|
||||
IN BOOLEAN Enable,
|
||||
IN EFI_TIME *Time OPTIONAL
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: SetWakeupTime is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3SetVirtualAddressMap (
|
||||
IN UINTN MemoryMapSize,
|
||||
IN UINTN DescriptorSize,
|
||||
IN UINT32 DescriptorVersion,
|
||||
IN EFI_MEMORY_DESCRIPTOR *VirtualMap
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: SetVirtualAddressMap is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3ConvertPointer (
|
||||
IN UINTN DebugDisposition,
|
||||
IN OUT VOID **Address
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: ConvertPointer is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetVariable (
|
||||
IN CHAR16 *VariableName,
|
||||
IN EFI_GUID *VendorGuid,
|
||||
OUT UINT32 *Attributes OPTIONAL,
|
||||
IN OUT UINTN *DataSize,
|
||||
OUT VOID *Data OPTIONAL
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallGetVariable,
|
||||
VariableName,
|
||||
VendorGuid,
|
||||
Attributes,
|
||||
DataSize,
|
||||
Data
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetNextVariableName (
|
||||
IN OUT UINTN *VariableNameSize,
|
||||
IN OUT CHAR16 *VariableName,
|
||||
IN OUT EFI_GUID *VendorGuid
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: GetNextVariableName is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3SetVariable (
|
||||
IN CHAR16 *VariableName,
|
||||
IN EFI_GUID *VendorGuid,
|
||||
IN UINT32 Attributes,
|
||||
IN UINTN DataSize,
|
||||
IN VOID *Data
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: SetVariable is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetNextHighMonotonicCount (
|
||||
OUT UINT32 *HighCount
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: GetNextHighMonotonicCount is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3ResetSystem (
|
||||
IN EFI_RESET_TYPE ResetType,
|
||||
IN EFI_STATUS ResetStatus,
|
||||
IN UINTN DataSize,
|
||||
IN VOID *ResetData OPTIONAL
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: ResetSystem is not supported\n"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3UpdateCapsule (
|
||||
IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
|
||||
IN UINTN CapsuleCount,
|
||||
IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: UpdateCapsule is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3QueryCapsuleCapabilities (
|
||||
IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
|
||||
IN UINTN CapsuleCount,
|
||||
OUT UINT64 *MaximumCapsuleSize,
|
||||
OUT EFI_RESET_TYPE *ResetType
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: QueryCapsuleCapabilities is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3QueryVariableInfo (
|
||||
IN UINT32 Attributes,
|
||||
OUT UINT64 *MaximumVariableStorageSize,
|
||||
OUT UINT64 *RemainingVariableStorageSize,
|
||||
OUT UINT64 *MaximumVariableSize
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: QueryVariableInfo is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
#include <Uefi.h>
|
||||
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
|
||||
#include "Ring3.h"
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetTime (
|
||||
OUT EFI_TIME *Time,
|
||||
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: GetTime is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3SetTime (
|
||||
IN EFI_TIME *Time
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: SetTime is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetWakeupTime (
|
||||
OUT BOOLEAN *Enabled,
|
||||
OUT BOOLEAN *Pending,
|
||||
OUT EFI_TIME *Time
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: GetWakeupTime is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3SetWakeupTime (
|
||||
IN BOOLEAN Enable,
|
||||
IN EFI_TIME *Time OPTIONAL
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: SetWakeupTime is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3SetVirtualAddressMap (
|
||||
IN UINTN MemoryMapSize,
|
||||
IN UINTN DescriptorSize,
|
||||
IN UINT32 DescriptorVersion,
|
||||
IN EFI_MEMORY_DESCRIPTOR *VirtualMap
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: SetVirtualAddressMap is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3ConvertPointer (
|
||||
IN UINTN DebugDisposition,
|
||||
IN OUT VOID **Address
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: ConvertPointer is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetVariable (
|
||||
IN CHAR16 *VariableName,
|
||||
IN EFI_GUID *VendorGuid,
|
||||
OUT UINT32 *Attributes OPTIONAL,
|
||||
IN OUT UINTN *DataSize,
|
||||
OUT VOID *Data OPTIONAL
|
||||
)
|
||||
{
|
||||
return SysCall (
|
||||
SysCallGetVariable,
|
||||
VariableName,
|
||||
VendorGuid,
|
||||
Attributes,
|
||||
DataSize,
|
||||
Data
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetNextVariableName (
|
||||
IN OUT UINTN *VariableNameSize,
|
||||
IN OUT CHAR16 *VariableName,
|
||||
IN OUT EFI_GUID *VendorGuid
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: GetNextVariableName is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3SetVariable (
|
||||
IN CHAR16 *VariableName,
|
||||
IN EFI_GUID *VendorGuid,
|
||||
IN UINT32 Attributes,
|
||||
IN UINTN DataSize,
|
||||
IN VOID *Data
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: SetVariable is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3GetNextHighMonotonicCount (
|
||||
OUT UINT32 *HighCount
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: GetNextHighMonotonicCount is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
Ring3ResetSystem (
|
||||
IN EFI_RESET_TYPE ResetType,
|
||||
IN EFI_STATUS ResetStatus,
|
||||
IN UINTN DataSize,
|
||||
IN VOID *ResetData OPTIONAL
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: ResetSystem is not supported\n"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3UpdateCapsule (
|
||||
IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
|
||||
IN UINTN CapsuleCount,
|
||||
IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: UpdateCapsule is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3QueryCapsuleCapabilities (
|
||||
IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
|
||||
IN UINTN CapsuleCount,
|
||||
OUT UINT64 *MaximumCapsuleSize,
|
||||
OUT EFI_RESET_TYPE *ResetType
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: QueryCapsuleCapabilities is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Ring3QueryVariableInfo (
|
||||
IN UINT32 Attributes,
|
||||
OUT UINT64 *MaximumVariableStorageSize,
|
||||
OUT UINT64 *RemainingVariableStorageSize,
|
||||
OUT UINT64 *MaximumVariableSize
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "Ring3: QueryVariableInfo is not supported\n"));
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
;------------------------------------------------------------------------------
|
||||
; Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
extern ASM_PFX(Ring3Call)
|
||||
|
||||
DEFAULT REL
|
||||
SECTION .text
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; SysCall (
|
||||
; IN UINT8 Type,
|
||||
; ...
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(SysCall)
|
||||
ASM_PFX(SysCall):
|
||||
; Save Type for CoreBootServices().
|
||||
mov r10, rcx
|
||||
|
||||
; SYSCALL saves RFLAGS into R11 and the RIP of the next instruction into RCX.
|
||||
syscall
|
||||
; SYSRET copies the value in RCX into RIP and loads RFLAGS from R11.
|
||||
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; Ring3EntryPoint (
|
||||
; IN RING3_CALL_DATA *Data
|
||||
; );
|
||||
;
|
||||
; (rcx) RIP of Ring3EntryPoint saved for SYSRET in CallRing3().
|
||||
; (rdx) Data
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(Ring3EntryPoint)
|
||||
ASM_PFX(Ring3EntryPoint):
|
||||
mov rcx, rdx
|
||||
|
||||
call ASM_PFX(Ring3Call)
|
||||
;------------------------------------------------------------------------------
|
||||
; Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
extern ASM_PFX(Ring3Call)
|
||||
|
||||
DEFAULT REL
|
||||
SECTION .text
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; SysCall (
|
||||
; IN UINT8 Type,
|
||||
; ...
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(SysCall)
|
||||
ASM_PFX(SysCall):
|
||||
; Save Type for CoreBootServices().
|
||||
mov r10, rcx
|
||||
|
||||
; SYSCALL saves RFLAGS into R11 and the RIP of the next instruction into RCX.
|
||||
syscall
|
||||
; SYSRET copies the value in RCX into RIP and loads RFLAGS from R11.
|
||||
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; Ring3EntryPoint (
|
||||
; IN RING3_CALL_DATA *Data
|
||||
; );
|
||||
;
|
||||
; (rcx) RIP of Ring3EntryPoint saved for SYSRET in CallRing3().
|
||||
; (rdx) Data
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(Ring3EntryPoint)
|
||||
ASM_PFX(Ring3EntryPoint):
|
||||
mov rcx, rdx
|
||||
|
||||
call ASM_PFX(Ring3Call)
|
||||
|
|
|
@ -1,169 +1,169 @@
|
|||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <AsmMacroIoLibV8.h>
|
||||
|
||||
.cpu cortex-a76
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// CallInstallMultipleProtocolInterfaces (
|
||||
// IN EFI_HANDLE *Handle,
|
||||
// IN VOID **ArgList,
|
||||
// IN UINT32 ArgListSize,
|
||||
// IN VOID *Function
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(CallInstallMultipleProtocolInterfaces)
|
||||
stp x29, x30, [sp, #-0x10]!
|
||||
mov x29, sp
|
||||
// Save function input.
|
||||
mov x9, x1
|
||||
mov x10, x2
|
||||
mov x11, x3
|
||||
// Prepare registers for call.
|
||||
ldp x1, x2, [x9]
|
||||
ldp x3, x4, [x9, #0x10]
|
||||
ldp x5, x6, [x9, #0x20]
|
||||
ldr x7, [x9, #0x30]
|
||||
// Prepare stack for call.
|
||||
cmp x10, #7
|
||||
b.le call
|
||||
add x9, x9, x10, LSL #3
|
||||
sub x10, x10, #7
|
||||
tst x10, #1
|
||||
b.eq copy
|
||||
// To align stack on 16 bytes.
|
||||
add x9, x9, #0x8
|
||||
add x10, x10, #1
|
||||
copy:
|
||||
ldp x12, x13, [x9, #-0x10]!
|
||||
stp x12, x13, [sp, #-0x10]!
|
||||
subs x10, x10, #2
|
||||
b.ne copy
|
||||
|
||||
call:
|
||||
blr x11
|
||||
|
||||
mov sp, x29
|
||||
ldp x29, x30, [sp]
|
||||
add sp, sp, #0x10
|
||||
ret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// CallRing3 (
|
||||
// IN RING3_CALL_DATA *Data
|
||||
// );
|
||||
//
|
||||
// (x0) Data
|
||||
// (x1) gRing3CallStackTop
|
||||
// (x2) gRing3EntryPoint
|
||||
// (x3) gCoreSysCallStackTop
|
||||
// (x4) &CoreSp
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmCallRing3)
|
||||
// Save registers.
|
||||
sub sp, sp, #0x100
|
||||
|
||||
stp q8, q9, [sp, #0xe0]
|
||||
stp q10, q11, [sp, #0xc0]
|
||||
stp q12, q13, [sp, #0xa0]
|
||||
stp q14, q15, [sp, #0x80]
|
||||
|
||||
stp xzr, x16, [sp, #0x70]
|
||||
stp x17, x18, [sp, #0x60]
|
||||
stp x19, x20, [sp, #0x50]
|
||||
stp x21, x22, [sp, #0x40]
|
||||
stp x23, x24, [sp, #0x30]
|
||||
stp x25, x26, [sp, #0x20]
|
||||
stp x27, x28, [sp, #0x10]
|
||||
stp x29, x30, [sp]
|
||||
// Disable interrupts.
|
||||
msr daifset, #0xf
|
||||
isb
|
||||
// Prepare Ring3 SP and EntryPoint.
|
||||
msr sp_el0, x1
|
||||
msr elr_el1, x2
|
||||
// Save Core SP and switch to CoreSysCall Stack.
|
||||
mov x5, sp
|
||||
str x5, [x4]
|
||||
mov sp, x3
|
||||
// Copy PSTATE to SPSR.
|
||||
mrs x1, nzcv
|
||||
mrs x2, pan
|
||||
orr x1, x1, x2
|
||||
//
|
||||
// M[3:0], bits [3:0] AArch64 Exception level and selected Stack Pointer.
|
||||
// 0b0000 - EL0.
|
||||
// 0b0100 - EL1 with SP_EL0 (ELt).
|
||||
// 0b0101 - EL1 with SP_EL1 (EL1h).
|
||||
//
|
||||
msr spsr_el1, x1
|
||||
isb
|
||||
dsb sy
|
||||
eret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ReturnToCore (
|
||||
// IN EFI_STATUS Status,
|
||||
// IN UINTN CoreSp
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ReturnToCore)
|
||||
// Zero Exception Syndrome Register to prevent QEMU from random crashing.
|
||||
msr esr_el1, xzr
|
||||
msr spsr_el1, xzr
|
||||
msr elr_el1, xzr
|
||||
msr far_el1, xzr
|
||||
// Switch to Core Stack.
|
||||
mov sp, x1
|
||||
// Restore registers and Stack.
|
||||
ldp q8, q9, [sp, #0xe0]
|
||||
ldp q10, q11, [sp, #0xc0]
|
||||
ldp q12, q13, [sp, #0xa0]
|
||||
ldp q14, q15, [sp, #0x80]
|
||||
|
||||
ldr x16, [sp, #0x78]
|
||||
ldp x17, x18, [sp, #0x60]
|
||||
ldp x19, x20, [sp, #0x50]
|
||||
ldp x21, x22, [sp, #0x40]
|
||||
ldp x23, x24, [sp, #0x30]
|
||||
ldp x25, x26, [sp, #0x20]
|
||||
ldp x27, x28, [sp, #0x10]
|
||||
ldp x29, x30, [sp]
|
||||
add sp, sp, #0x100
|
||||
// Enable interrupts.
|
||||
msr daifclr, #0xf
|
||||
isb
|
||||
ret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ArmSetPan (
|
||||
// VOID
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmSetPan)
|
||||
msr pan, #1
|
||||
ret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ArmClearPan (
|
||||
// VOID
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmClearPan)
|
||||
msr pan, #0
|
||||
ret
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <AsmMacroIoLibV8.h>
|
||||
|
||||
.cpu cortex-a76
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// CallInstallMultipleProtocolInterfaces (
|
||||
// IN EFI_HANDLE *Handle,
|
||||
// IN VOID **ArgList,
|
||||
// IN UINT32 ArgListSize,
|
||||
// IN VOID *Function
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(CallInstallMultipleProtocolInterfaces)
|
||||
stp x29, x30, [sp, #-0x10]!
|
||||
mov x29, sp
|
||||
// Save function input.
|
||||
mov x9, x1
|
||||
mov x10, x2
|
||||
mov x11, x3
|
||||
// Prepare registers for call.
|
||||
ldp x1, x2, [x9]
|
||||
ldp x3, x4, [x9, #0x10]
|
||||
ldp x5, x6, [x9, #0x20]
|
||||
ldr x7, [x9, #0x30]
|
||||
// Prepare stack for call.
|
||||
cmp x10, #7
|
||||
b.le call
|
||||
add x9, x9, x10, LSL #3
|
||||
sub x10, x10, #7
|
||||
tst x10, #1
|
||||
b.eq copy
|
||||
// To align stack on 16 bytes.
|
||||
add x9, x9, #0x8
|
||||
add x10, x10, #1
|
||||
copy:
|
||||
ldp x12, x13, [x9, #-0x10]!
|
||||
stp x12, x13, [sp, #-0x10]!
|
||||
subs x10, x10, #2
|
||||
b.ne copy
|
||||
|
||||
call:
|
||||
blr x11
|
||||
|
||||
mov sp, x29
|
||||
ldp x29, x30, [sp]
|
||||
add sp, sp, #0x10
|
||||
ret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// CallRing3 (
|
||||
// IN RING3_CALL_DATA *Data
|
||||
// );
|
||||
//
|
||||
// (x0) Data
|
||||
// (x1) gRing3CallStackTop
|
||||
// (x2) gRing3EntryPoint
|
||||
// (x3) gCoreSysCallStackTop
|
||||
// (x4) &CoreSp
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmCallRing3)
|
||||
// Save registers.
|
||||
sub sp, sp, #0x100
|
||||
|
||||
stp q8, q9, [sp, #0xe0]
|
||||
stp q10, q11, [sp, #0xc0]
|
||||
stp q12, q13, [sp, #0xa0]
|
||||
stp q14, q15, [sp, #0x80]
|
||||
|
||||
stp xzr, x16, [sp, #0x70]
|
||||
stp x17, x18, [sp, #0x60]
|
||||
stp x19, x20, [sp, #0x50]
|
||||
stp x21, x22, [sp, #0x40]
|
||||
stp x23, x24, [sp, #0x30]
|
||||
stp x25, x26, [sp, #0x20]
|
||||
stp x27, x28, [sp, #0x10]
|
||||
stp x29, x30, [sp]
|
||||
// Disable interrupts.
|
||||
msr daifset, #0xf
|
||||
isb
|
||||
// Prepare Ring3 SP and EntryPoint.
|
||||
msr sp_el0, x1
|
||||
msr elr_el1, x2
|
||||
// Save Core SP and switch to CoreSysCall Stack.
|
||||
mov x5, sp
|
||||
str x5, [x4]
|
||||
mov sp, x3
|
||||
// Copy PSTATE to SPSR.
|
||||
mrs x1, nzcv
|
||||
mrs x2, pan
|
||||
orr x1, x1, x2
|
||||
//
|
||||
// M[3:0], bits [3:0] AArch64 Exception level and selected Stack Pointer.
|
||||
// 0b0000 - EL0.
|
||||
// 0b0100 - EL1 with SP_EL0 (ELt).
|
||||
// 0b0101 - EL1 with SP_EL1 (EL1h).
|
||||
//
|
||||
msr spsr_el1, x1
|
||||
isb
|
||||
dsb sy
|
||||
eret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ReturnToCore (
|
||||
// IN EFI_STATUS Status,
|
||||
// IN UINTN CoreSp
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ReturnToCore)
|
||||
// Zero Exception Syndrome Register to prevent QEMU from random crashing.
|
||||
msr esr_el1, xzr
|
||||
msr spsr_el1, xzr
|
||||
msr elr_el1, xzr
|
||||
msr far_el1, xzr
|
||||
// Switch to Core Stack.
|
||||
mov sp, x1
|
||||
// Restore registers and Stack.
|
||||
ldp q8, q9, [sp, #0xe0]
|
||||
ldp q10, q11, [sp, #0xc0]
|
||||
ldp q12, q13, [sp, #0xa0]
|
||||
ldp q14, q15, [sp, #0x80]
|
||||
|
||||
ldr x16, [sp, #0x78]
|
||||
ldp x17, x18, [sp, #0x60]
|
||||
ldp x19, x20, [sp, #0x50]
|
||||
ldp x21, x22, [sp, #0x40]
|
||||
ldp x23, x24, [sp, #0x30]
|
||||
ldp x25, x26, [sp, #0x20]
|
||||
ldp x27, x28, [sp, #0x10]
|
||||
ldp x29, x30, [sp]
|
||||
add sp, sp, #0x100
|
||||
// Enable interrupts.
|
||||
msr daifclr, #0xf
|
||||
isb
|
||||
ret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ArmSetPan (
|
||||
// VOID
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmSetPan)
|
||||
msr pan, #1
|
||||
ret
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ArmClearPan (
|
||||
// VOID
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmClearPan)
|
||||
msr pan, #0
|
||||
ret
|
||||
|
|
|
@ -1,210 +1,210 @@
|
|||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include <Chipset/AArch64.h>
|
||||
#include <Guid/EarlyPL011BaseAddress.h>
|
||||
#include <Library/ArmLib.h>
|
||||
#include <Library/DefaultExceptionHandlerLib.h>
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
STATIC UINTN mCoreSp;
|
||||
UINTN gUartBaseAddress;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArmCallRing3 (
|
||||
IN RING3_CALL_DATA *Data,
|
||||
IN VOID *StackPointer,
|
||||
IN VOID *EntryPoint,
|
||||
IN VOID *SysCallStack,
|
||||
IN VOID *CoreStack
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ReturnToCore (
|
||||
IN EFI_STATUS Status,
|
||||
IN UINTN CoreSp
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmSetPan (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmClearPan (
|
||||
VOID
|
||||
);
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SysCallBootService (
|
||||
IN UINT8 Type,
|
||||
IN VOID *CoreRbp,
|
||||
IN VOID *UserRsp
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_PHYSICAL_ADDRESS Physical;
|
||||
|
||||
if (Type == SysCallReturnToCore) {
|
||||
ReturnToCore (*(EFI_STATUS *)CoreRbp, mCoreSp);
|
||||
}
|
||||
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
EFI_SIZE_TO_PAGES (9 * sizeof (UINTN)),
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
DisableSMAP ();
|
||||
CopyMem ((VOID *)((UINTN)Physical + sizeof (UINTN)), (VOID *)UserRsp, 8 * sizeof (UINTN));
|
||||
|
||||
SetUefiImageMemoryAttributes (
|
||||
gUartBaseAddress,
|
||||
EFI_PAGE_SIZE,
|
||||
EFI_MEMORY_XP
|
||||
);
|
||||
EnableSMAP ();
|
||||
|
||||
Status = CallBootService (
|
||||
Type,
|
||||
(CORE_STACK *)CoreRbp,
|
||||
(RING3_STACK *)(UINTN)Physical
|
||||
);
|
||||
|
||||
SetUefiImageMemoryAttributes (
|
||||
gUartBaseAddress,
|
||||
EFI_PAGE_SIZE,
|
||||
EFI_MEMORY_XP | EFI_MEMORY_USER
|
||||
);
|
||||
|
||||
CoreFreePages (Physical, EFI_SIZE_TO_PAGES (9 * sizeof (UINTN)));
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
)
|
||||
{
|
||||
UINTN Tcr;
|
||||
UINTN Index;
|
||||
EARLY_PL011_BASE_ADDRESS *UartBase;
|
||||
EFI_PHYSICAL_ADDRESS Physical;
|
||||
EFI_HOB_GENERIC_HEADER *Ring3Hob;
|
||||
UINT16 HobLength;
|
||||
EFI_STATUS Status;
|
||||
//
|
||||
// If HCR_EL2.NV is 1 and the current Exception level is EL1,
|
||||
// then EL1 read accesses to the CurrentEL register return a value of 0x2 in bits[3:2].
|
||||
// CurrentEL == 1 -> HCR_EL2.NV == 0
|
||||
//
|
||||
// If stage 1 is enabled and stage 1 Base permissions use Direct permissions,
|
||||
// then GCS access is not permitted and UnprivGCS and PrivGCS are not present.
|
||||
//
|
||||
// Disable Hierarchical permissions just in case.
|
||||
//
|
||||
Tcr = ArmGetTCR ();
|
||||
Tcr |= TCR_EL1_HPD0_MASK | TCR_EL1_HPD1_MASK;
|
||||
ArmSetTCR (Tcr);
|
||||
//
|
||||
// Problem 1: Uart is memory maped.
|
||||
//
|
||||
for (Index = 0; Index < NumberOfEntries; ++Index) {
|
||||
if (CompareGuid (&gEfiHobListGuid, &(Table[Index].VendorGuid))) {
|
||||
UartBase = GET_GUID_HOB_DATA (Table[Index].VendorTable);
|
||||
gUartBaseAddress = UartBase->DebugAddress;
|
||||
//
|
||||
// Copy Hob into Ring3.
|
||||
//
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
1,
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3Hob.\n"));
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
DEBUG ((DEBUG_ERROR, "UartBaseAddress = %p.\n", gUartBaseAddress));
|
||||
|
||||
Ring3Hob = (EFI_HOB_GENERIC_HEADER *)(UINTN)Physical;
|
||||
|
||||
HobLength = (UINT16)((sizeof (EFI_HOB_GUID_TYPE) + sizeof (EARLY_PL011_BASE_ADDRESS) + 0x7) & (~0x7));
|
||||
|
||||
Ring3Hob->HobType = EFI_HOB_TYPE_GUID_EXTENSION;
|
||||
Ring3Hob->HobLength = HobLength;
|
||||
Ring3Hob->Reserved = 0;
|
||||
|
||||
CopyGuid (&((EFI_HOB_GUID_TYPE *)Ring3Hob)->Name, &gEarlyPL011BaseAddressGuid);
|
||||
|
||||
Ring3Hob = (EFI_HOB_GENERIC_HEADER *)((UINTN)Ring3Hob + HobLength);
|
||||
|
||||
Ring3Hob->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
|
||||
Ring3Hob->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
|
||||
Ring3Hob->Reserved = 0;
|
||||
|
||||
Table[Index].VendorTable = (VOID *)(UINTN)Physical;
|
||||
UartBase = GET_GUID_HOB_DATA (Table[Index].VendorTable);
|
||||
UartBase->DebugAddress = gUartBaseAddress;
|
||||
}
|
||||
}
|
||||
|
||||
if (ArmHasPan ()) {
|
||||
//
|
||||
// Enable Privileged Access Never feature.
|
||||
//
|
||||
ArmSetPan ();
|
||||
}
|
||||
|
||||
InitializeSysCallHandler ((VOID *)SysCallBootService);
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
DisableSMAP (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (ArmHasPan ()) {
|
||||
ArmClearPan ();
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
EnableSMAP (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (ArmHasPan ()) {
|
||||
ArmSetPan ();
|
||||
}
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CallRing3 (
|
||||
IN RING3_CALL_DATA *Data
|
||||
)
|
||||
{
|
||||
return ArmCallRing3 (Data, gRing3CallStackTop, gRing3EntryPoint, gCoreSysCallStackTop, &mCoreSp);
|
||||
}
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include <Chipset/AArch64.h>
|
||||
#include <Guid/EarlyPL011BaseAddress.h>
|
||||
#include <Library/ArmLib.h>
|
||||
#include <Library/DefaultExceptionHandlerLib.h>
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
STATIC UINTN mCoreSp;
|
||||
UINTN gUartBaseAddress;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArmCallRing3 (
|
||||
IN RING3_CALL_DATA *Data,
|
||||
IN VOID *StackPointer,
|
||||
IN VOID *EntryPoint,
|
||||
IN VOID *SysCallStack,
|
||||
IN VOID *CoreStack
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ReturnToCore (
|
||||
IN EFI_STATUS Status,
|
||||
IN UINTN CoreSp
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmSetPan (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmClearPan (
|
||||
VOID
|
||||
);
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SysCallBootService (
|
||||
IN UINT8 Type,
|
||||
IN VOID *CoreRbp,
|
||||
IN VOID *UserRsp
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_PHYSICAL_ADDRESS Physical;
|
||||
|
||||
if (Type == SysCallReturnToCore) {
|
||||
ReturnToCore (*(EFI_STATUS *)CoreRbp, mCoreSp);
|
||||
}
|
||||
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
EFI_SIZE_TO_PAGES (9 * sizeof (UINTN)),
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
DisableSMAP ();
|
||||
CopyMem ((VOID *)((UINTN)Physical + sizeof (UINTN)), (VOID *)UserRsp, 8 * sizeof (UINTN));
|
||||
|
||||
SetUefiImageMemoryAttributes (
|
||||
gUartBaseAddress,
|
||||
EFI_PAGE_SIZE,
|
||||
EFI_MEMORY_XP
|
||||
);
|
||||
EnableSMAP ();
|
||||
|
||||
Status = CallBootService (
|
||||
Type,
|
||||
(CORE_STACK *)CoreRbp,
|
||||
(RING3_STACK *)(UINTN)Physical
|
||||
);
|
||||
|
||||
SetUefiImageMemoryAttributes (
|
||||
gUartBaseAddress,
|
||||
EFI_PAGE_SIZE,
|
||||
EFI_MEMORY_XP | EFI_MEMORY_USER
|
||||
);
|
||||
|
||||
CoreFreePages (Physical, EFI_SIZE_TO_PAGES (9 * sizeof (UINTN)));
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
)
|
||||
{
|
||||
UINTN Tcr;
|
||||
UINTN Index;
|
||||
EARLY_PL011_BASE_ADDRESS *UartBase;
|
||||
EFI_PHYSICAL_ADDRESS Physical;
|
||||
EFI_HOB_GENERIC_HEADER *Ring3Hob;
|
||||
UINT16 HobLength;
|
||||
EFI_STATUS Status;
|
||||
//
|
||||
// If HCR_EL2.NV is 1 and the current Exception level is EL1,
|
||||
// then EL1 read accesses to the CurrentEL register return a value of 0x2 in bits[3:2].
|
||||
// CurrentEL == 1 -> HCR_EL2.NV == 0
|
||||
//
|
||||
// If stage 1 is enabled and stage 1 Base permissions use Direct permissions,
|
||||
// then GCS access is not permitted and UnprivGCS and PrivGCS are not present.
|
||||
//
|
||||
// Disable Hierarchical permissions just in case.
|
||||
//
|
||||
Tcr = ArmGetTCR ();
|
||||
Tcr |= TCR_EL1_HPD0_MASK | TCR_EL1_HPD1_MASK;
|
||||
ArmSetTCR (Tcr);
|
||||
//
|
||||
// Problem 1: Uart is memory maped.
|
||||
//
|
||||
for (Index = 0; Index < NumberOfEntries; ++Index) {
|
||||
if (CompareGuid (&gEfiHobListGuid, &(Table[Index].VendorGuid))) {
|
||||
UartBase = GET_GUID_HOB_DATA (Table[Index].VendorTable);
|
||||
gUartBaseAddress = UartBase->DebugAddress;
|
||||
//
|
||||
// Copy Hob into Ring3.
|
||||
//
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
1,
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3Hob.\n"));
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
DEBUG ((DEBUG_ERROR, "UartBaseAddress = %p.\n", gUartBaseAddress));
|
||||
|
||||
Ring3Hob = (EFI_HOB_GENERIC_HEADER *)(UINTN)Physical;
|
||||
|
||||
HobLength = (UINT16)((sizeof (EFI_HOB_GUID_TYPE) + sizeof (EARLY_PL011_BASE_ADDRESS) + 0x7) & (~0x7));
|
||||
|
||||
Ring3Hob->HobType = EFI_HOB_TYPE_GUID_EXTENSION;
|
||||
Ring3Hob->HobLength = HobLength;
|
||||
Ring3Hob->Reserved = 0;
|
||||
|
||||
CopyGuid (&((EFI_HOB_GUID_TYPE *)Ring3Hob)->Name, &gEarlyPL011BaseAddressGuid);
|
||||
|
||||
Ring3Hob = (EFI_HOB_GENERIC_HEADER *)((UINTN)Ring3Hob + HobLength);
|
||||
|
||||
Ring3Hob->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
|
||||
Ring3Hob->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
|
||||
Ring3Hob->Reserved = 0;
|
||||
|
||||
Table[Index].VendorTable = (VOID *)(UINTN)Physical;
|
||||
UartBase = GET_GUID_HOB_DATA (Table[Index].VendorTable);
|
||||
UartBase->DebugAddress = gUartBaseAddress;
|
||||
}
|
||||
}
|
||||
|
||||
if (ArmHasPan ()) {
|
||||
//
|
||||
// Enable Privileged Access Never feature.
|
||||
//
|
||||
ArmSetPan ();
|
||||
}
|
||||
|
||||
InitializeSysCallHandler ((VOID *)SysCallBootService);
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
DisableSMAP (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (ArmHasPan ()) {
|
||||
ArmClearPan ();
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
EnableSMAP (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (ArmHasPan ()) {
|
||||
ArmSetPan ();
|
||||
}
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CallRing3 (
|
||||
IN RING3_CALL_DATA *Data
|
||||
)
|
||||
{
|
||||
return ArmCallRing3 (Data, gRing3CallStackTop, gRing3EntryPoint, gCoreSysCallStackTop, &mCoreSp);
|
||||
}
|
||||
|
|
|
@ -1,148 +1,148 @@
|
|||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <AsmMacroIoLib.h>
|
||||
|
||||
.arch armv8.1a
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// CallInstallMultipleProtocolInterfaces (
|
||||
// IN EFI_HANDLE *Handle,
|
||||
// IN VOID **ArgList,
|
||||
// IN UINT32 ArgListSize,
|
||||
// IN VOID *Function
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(CallInstallMultipleProtocolInterfaces)
|
||||
push {R4-R8, LR}
|
||||
mov R7, SP
|
||||
// Save function input.
|
||||
mov R4, R3
|
||||
mov R5, R1
|
||||
mov R6, R2
|
||||
// Prepare registers for call.
|
||||
ldmfd R5, {R1-R3}
|
||||
// Prepare stack for call.
|
||||
cmp R6, #3
|
||||
ble call
|
||||
|
||||
add R5, R5, R6, LSL #2
|
||||
sub R6, R6, #3
|
||||
tst R6, #1
|
||||
beq copy
|
||||
// To align stack on 8 bytes.
|
||||
add R5, R5, #0x4
|
||||
add R6, R6, #1
|
||||
copy:
|
||||
sub R5, R5, #0x4
|
||||
ldmfd R5, {R8}
|
||||
push {R8}
|
||||
subs R6, R6, #1
|
||||
bne copy
|
||||
|
||||
call:
|
||||
blx R4
|
||||
|
||||
mov SP, R7
|
||||
pop {R4-R8, LR}
|
||||
bx LR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// CallRing3 (
|
||||
// IN RING3_CALL_DATA *Data
|
||||
// );
|
||||
//
|
||||
// (r0) Data
|
||||
// (r1) gRing3CallStackTop
|
||||
// (r2) gRing3EntryPoint
|
||||
// (r3) gCoreSysCallStackTop
|
||||
//
|
||||
// (On Core Stack) &CoreSp
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmCallRing3)
|
||||
// Save registers.
|
||||
push {R4-R12, LR}
|
||||
// R6 is &CoreSp
|
||||
ldr R6, [SP, #0x28]
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <AsmMacroIoLib.h>
|
||||
|
||||
.arch armv8.1a
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// CallInstallMultipleProtocolInterfaces (
|
||||
// IN EFI_HANDLE *Handle,
|
||||
// IN VOID **ArgList,
|
||||
// IN UINT32 ArgListSize,
|
||||
// IN VOID *Function
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(CallInstallMultipleProtocolInterfaces)
|
||||
push {R4-R8, LR}
|
||||
mov R7, SP
|
||||
// Save function input.
|
||||
mov R4, R3
|
||||
mov R5, R1
|
||||
mov R6, R2
|
||||
// Prepare registers for call.
|
||||
ldmfd R5, {R1-R3}
|
||||
// Prepare stack for call.
|
||||
cmp R6, #3
|
||||
ble call
|
||||
|
||||
add R5, R5, R6, LSL #2
|
||||
sub R6, R6, #3
|
||||
tst R6, #1
|
||||
beq copy
|
||||
// To align stack on 8 bytes.
|
||||
add R5, R5, #0x4
|
||||
add R6, R6, #1
|
||||
copy:
|
||||
sub R5, R5, #0x4
|
||||
ldmfd R5, {R8}
|
||||
push {R8}
|
||||
subs R6, R6, #1
|
||||
bne copy
|
||||
|
||||
call:
|
||||
blx R4
|
||||
|
||||
mov SP, R7
|
||||
pop {R4-R8, LR}
|
||||
bx LR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// EFI_STATUS
|
||||
// EFIAPI
|
||||
// CallRing3 (
|
||||
// IN RING3_CALL_DATA *Data
|
||||
// );
|
||||
//
|
||||
// (r0) Data
|
||||
// (r1) gRing3CallStackTop
|
||||
// (r2) gRing3EntryPoint
|
||||
// (r3) gCoreSysCallStackTop
|
||||
//
|
||||
// (On Core Stack) &CoreSp
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmCallRing3)
|
||||
// Save registers.
|
||||
push {R4-R12, LR}
|
||||
// R6 is &CoreSp
|
||||
ldr R6, [SP, #0x28]
|
||||
|
||||
#if (FixedPcdGet32(PcdVFPEnabled))
|
||||
// Save vstm registers in case they are used in optimizations.
|
||||
vpush {d0-d15}
|
||||
#endif
|
||||
|
||||
// Disable interrupts.
|
||||
mrs R4, CPSR
|
||||
cpsid if
|
||||
isb
|
||||
|
||||
// Set SP_usr to gRing3CallStackTop.
|
||||
push {R1}
|
||||
mov R1, SP
|
||||
ldmia R1, {SP}^
|
||||
pop {R1}
|
||||
// Set SPSR M[3:0] bits to User mode.
|
||||
and R4, R4, #0xFFFFFFF0
|
||||
|
||||
// Save Core SP and switch to CoreSysCall Stack.
|
||||
mov R5, SP
|
||||
str R5, [R6]
|
||||
mov SP, R3
|
||||
|
||||
push {R4}
|
||||
push {R2}
|
||||
rfefd SP
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ReturnToCore (
|
||||
// IN EFI_STATUS Status,
|
||||
// IN UINTN CoreSp
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ReturnToCore)
|
||||
// Switch to Core Stack.
|
||||
mov SP, R1
|
||||
|
||||
// Restore registers and Stack.
|
||||
|
||||
// Disable interrupts.
|
||||
mrs R4, CPSR
|
||||
cpsid if
|
||||
isb
|
||||
|
||||
// Set SP_usr to gRing3CallStackTop.
|
||||
push {R1}
|
||||
mov R1, SP
|
||||
ldmia R1, {SP}^
|
||||
pop {R1}
|
||||
// Set SPSR M[3:0] bits to User mode.
|
||||
and R4, R4, #0xFFFFFFF0
|
||||
|
||||
// Save Core SP and switch to CoreSysCall Stack.
|
||||
mov R5, SP
|
||||
str R5, [R6]
|
||||
mov SP, R3
|
||||
|
||||
push {R4}
|
||||
push {R2}
|
||||
rfefd SP
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ReturnToCore (
|
||||
// IN EFI_STATUS Status,
|
||||
// IN UINTN CoreSp
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ReturnToCore)
|
||||
// Switch to Core Stack.
|
||||
mov SP, R1
|
||||
|
||||
// Restore registers and Stack.
|
||||
#if (FixedPcdGet32(PcdVFPEnabled))
|
||||
vpop {d0-d15}
|
||||
#endif
|
||||
|
||||
pop {R4-R12, LR}
|
||||
|
||||
// Enable interrupts.
|
||||
cpsie if
|
||||
isb
|
||||
|
||||
bx LR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ArmSetPan (
|
||||
// VOID
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmSetPan)
|
||||
setpan #1
|
||||
bx LR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ArmClearPan (
|
||||
// VOID
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmClearPan)
|
||||
setpan #0
|
||||
bx LR
|
||||
|
||||
pop {R4-R12, LR}
|
||||
|
||||
// Enable interrupts.
|
||||
cpsie if
|
||||
isb
|
||||
|
||||
bx LR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ArmSetPan (
|
||||
// VOID
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmSetPan)
|
||||
setpan #1
|
||||
bx LR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VOID
|
||||
// EFIAPI
|
||||
// ArmClearPan (
|
||||
// VOID
|
||||
// );
|
||||
//------------------------------------------------------------------------------
|
||||
ASM_FUNC(ArmClearPan)
|
||||
setpan #0
|
||||
bx LR
|
||||
|
|
|
@ -1,145 +1,145 @@
|
|||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include <Library/ArmLib.h>
|
||||
#include <Library/DefaultExceptionHandlerLib.h>
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
STATIC UINTN mCoreSp;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArmCallRing3 (
|
||||
IN RING3_CALL_DATA *Data,
|
||||
IN VOID *StackPointer,
|
||||
IN VOID *EntryPoint,
|
||||
IN VOID *SysCallStack,
|
||||
IN VOID *CoreStack
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ReturnToCore (
|
||||
IN EFI_STATUS Status,
|
||||
IN UINTN CoreSp
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmSetPan (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmClearPan (
|
||||
VOID
|
||||
);
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SysCallBootService (
|
||||
IN UINT8 Type,
|
||||
IN VOID *CoreRbp,
|
||||
IN VOID *UserRsp
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_PHYSICAL_ADDRESS Physical;
|
||||
|
||||
if (Type == SysCallReturnToCore) {
|
||||
ReturnToCore (*(EFI_STATUS *)CoreRbp, mCoreSp);
|
||||
}
|
||||
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
EFI_SIZE_TO_PAGES (9 * sizeof (UINTN)),
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
DisableSMAP ();
|
||||
//
|
||||
// First 3 arguments are passed through R1-R3 and copied to SysCall Stack.
|
||||
//
|
||||
CopyMem ((VOID *)((UINTN)Physical + 2 * sizeof (UINTN)), (VOID *)CoreRbp, 3 * sizeof (UINTN));
|
||||
//
|
||||
// All remaining arguments are on User Stack.
|
||||
//
|
||||
CopyMem ((VOID *)((UINTN)Physical + 5 * sizeof (UINTN)), (VOID *)UserRsp, 4 * sizeof (UINTN));
|
||||
EnableSMAP ();
|
||||
|
||||
Status = CallBootService (
|
||||
Type,
|
||||
(CORE_STACK *)CoreRbp,
|
||||
(RING3_STACK *)(UINTN)Physical
|
||||
);
|
||||
|
||||
CoreFreePages (Physical, EFI_SIZE_TO_PAGES (9 * sizeof (UINTN)));
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
)
|
||||
{
|
||||
//
|
||||
// TODO: EFI_CONFIGURATION_TABLE, HOB_DATA, Uart are accessible to User.
|
||||
// Fix PageTable initialization.
|
||||
//
|
||||
if (ArmHasPan ()) {
|
||||
//
|
||||
// Enable Privileged Access Never feature.
|
||||
//
|
||||
ArmSetPan ();
|
||||
}
|
||||
|
||||
InitializeSysCallHandler (SysCallBootService);
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: Refactoring.
|
||||
//
|
||||
VOID
|
||||
EFIAPI
|
||||
DisableSMAP (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (ArmHasPan ()) {
|
||||
ArmClearPan ();
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
EnableSMAP (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (ArmHasPan ()) {
|
||||
ArmSetPan ();
|
||||
}
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CallRing3 (
|
||||
IN RING3_CALL_DATA *Data
|
||||
)
|
||||
{
|
||||
return ArmCallRing3 (Data, gRing3CallStackTop, gRing3EntryPoint, gCoreSysCallStackTop, &mCoreSp);
|
||||
}
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include <Library/ArmLib.h>
|
||||
#include <Library/DefaultExceptionHandlerLib.h>
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
STATIC UINTN mCoreSp;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArmCallRing3 (
|
||||
IN RING3_CALL_DATA *Data,
|
||||
IN VOID *StackPointer,
|
||||
IN VOID *EntryPoint,
|
||||
IN VOID *SysCallStack,
|
||||
IN VOID *CoreStack
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ReturnToCore (
|
||||
IN EFI_STATUS Status,
|
||||
IN UINTN CoreSp
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmSetPan (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArmClearPan (
|
||||
VOID
|
||||
);
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SysCallBootService (
|
||||
IN UINT8 Type,
|
||||
IN VOID *CoreRbp,
|
||||
IN VOID *UserRsp
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_PHYSICAL_ADDRESS Physical;
|
||||
|
||||
if (Type == SysCallReturnToCore) {
|
||||
ReturnToCore (*(EFI_STATUS *)CoreRbp, mCoreSp);
|
||||
}
|
||||
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
EFI_SIZE_TO_PAGES (9 * sizeof (UINTN)),
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
DisableSMAP ();
|
||||
//
|
||||
// First 3 arguments are passed through R1-R3 and copied to SysCall Stack.
|
||||
//
|
||||
CopyMem ((VOID *)((UINTN)Physical + 2 * sizeof (UINTN)), (VOID *)CoreRbp, 3 * sizeof (UINTN));
|
||||
//
|
||||
// All remaining arguments are on User Stack.
|
||||
//
|
||||
CopyMem ((VOID *)((UINTN)Physical + 5 * sizeof (UINTN)), (VOID *)UserRsp, 4 * sizeof (UINTN));
|
||||
EnableSMAP ();
|
||||
|
||||
Status = CallBootService (
|
||||
Type,
|
||||
(CORE_STACK *)CoreRbp,
|
||||
(RING3_STACK *)(UINTN)Physical
|
||||
);
|
||||
|
||||
CoreFreePages (Physical, EFI_SIZE_TO_PAGES (9 * sizeof (UINTN)));
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
)
|
||||
{
|
||||
//
|
||||
// TODO: EFI_CONFIGURATION_TABLE, HOB_DATA, Uart are accessible to User.
|
||||
// Fix PageTable initialization.
|
||||
//
|
||||
if (ArmHasPan ()) {
|
||||
//
|
||||
// Enable Privileged Access Never feature.
|
||||
//
|
||||
ArmSetPan ();
|
||||
}
|
||||
|
||||
InitializeSysCallHandler (SysCallBootService);
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: Refactoring.
|
||||
//
|
||||
VOID
|
||||
EFIAPI
|
||||
DisableSMAP (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (ArmHasPan ()) {
|
||||
ArmClearPan ();
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
EnableSMAP (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (ArmHasPan ()) {
|
||||
ArmSetPan ();
|
||||
}
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CallRing3 (
|
||||
IN RING3_CALL_DATA *Data
|
||||
)
|
||||
{
|
||||
return ArmCallRing3 (Data, gRing3CallStackTop, gRing3EntryPoint, gCoreSysCallStackTop, &mCoreSp);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,223 +1,223 @@
|
|||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
#include <Register/Intel/ArchitecturalMsr.h>
|
||||
|
||||
extern ASM_PFX(CallBootService)
|
||||
extern ASM_PFX(gCoreSysCallStackTop)
|
||||
extern ASM_PFX(gRing3CallStackTop)
|
||||
extern ASM_PFX(gRing3EntryPoint)
|
||||
|
||||
extern ASM_PFX(AsmReadMsr64)
|
||||
|
||||
DEFAULT REL
|
||||
SECTION .text
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; DisableSMAP (
|
||||
; VOID
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(DisableSMAP)
|
||||
ASM_PFX(DisableSMAP):
|
||||
pushfd
|
||||
pop eax
|
||||
or eax, 0x40000 ; Set AC (bit 18)
|
||||
push eax
|
||||
popfd
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; EnableSMAP (
|
||||
; VOID
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(EnableSMAP)
|
||||
ASM_PFX(EnableSMAP):
|
||||
pushfd
|
||||
pop eax
|
||||
and eax, ~0x40000 ; Clear AC (bit 18)
|
||||
push eax
|
||||
popfd
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CallInstallMultipleProtocolInterfaces (
|
||||
; IN EFI_HANDLE *Handle,
|
||||
; IN VOID **ArgList,
|
||||
; IN UINT32 ArgListSize,
|
||||
; IN VOID *Function
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CallInstallMultipleProtocolInterfaces)
|
||||
ASM_PFX(CallInstallMultipleProtocolInterfaces):
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
; Prepare stack for call.
|
||||
mov eax, [ebp + 3 * 4] ; eax = ArgList
|
||||
mov ecx, [ebp + 4 * 4] ; ecx = ArgListSize
|
||||
lea eax, [eax + ecx * 4]
|
||||
copy:
|
||||
sub eax, 4
|
||||
push dword [eax]
|
||||
sub ecx, 1
|
||||
jnz copy
|
||||
push dword [ebp + 2 * 4]
|
||||
|
||||
call [ebp + 5 * 4]
|
||||
|
||||
; Step over Function arguments.
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
|
||||
ret
|
||||
|
||||
%macro SetRing3DataSegmentSelectors 0
|
||||
push dword MSR_IA32_SYSENTER_CS
|
||||
call ASM_PFX(AsmReadMsr64)
|
||||
; eax = RING0_CODE32_SEL
|
||||
add eax, 24 ; GDT: RING0_CODE32, RING0_DATA32, RING3_CODE32, RING3_DATA32
|
||||
or eax, 3 ; RPL = 3
|
||||
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
pop eax
|
||||
%endmacro
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CoreBootServices (
|
||||
; IN UINT8 Type,
|
||||
; ...
|
||||
; );
|
||||
;
|
||||
; (eax) User return address.
|
||||
; (ecx) Type.
|
||||
; (edx) User Stack Pointer.
|
||||
;
|
||||
; (On User Stack) Argument 1, 2, ...
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CoreBootServices)
|
||||
ASM_PFX(CoreBootServices):
|
||||
; Save User return address and Stack pointers.
|
||||
push edx
|
||||
push ebp
|
||||
push eax
|
||||
|
||||
; Switch from User to Core data segment selectors.
|
||||
mov ax, ss
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
; Special case for SysCallReturnToCore.
|
||||
cmp ecx, 0
|
||||
je coreReturnAddress
|
||||
|
||||
; Prepare CallBootService arguments.
|
||||
call ASM_PFX(DisableSMAP)
|
||||
mov eax, [edx + 4 * 4] ; User Argument 3
|
||||
push eax
|
||||
mov eax, [edx + 3 * 4] ; User Argument 2
|
||||
push eax
|
||||
mov eax, [edx + 2 * 4] ; User Argument 1
|
||||
push eax
|
||||
call ASM_PFX(EnableSMAP)
|
||||
mov ebp, esp
|
||||
push edx
|
||||
push ebp
|
||||
push ecx
|
||||
|
||||
sti
|
||||
call ASM_PFX(CallBootService)
|
||||
push eax
|
||||
cli
|
||||
|
||||
SetRing3DataSegmentSelectors
|
||||
|
||||
pop eax
|
||||
|
||||
; Step over User Arguments [1..3] and CallBootService input.
|
||||
add esp, 4*6
|
||||
|
||||
; Prepare SYSEXIT arguments.
|
||||
pop edx ; User return address.
|
||||
pop ebp
|
||||
pop ecx ; User Stack Pointer.
|
||||
|
||||
sti
|
||||
sysexit
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CallRing3 (
|
||||
; IN RING3_CALL_DATA *Data
|
||||
; );
|
||||
;
|
||||
; (On User Stack) Data
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CallRing3)
|
||||
ASM_PFX(CallRing3):
|
||||
cli
|
||||
; Save nonvolatile registers EBX, EBP, EDI, ESI, ESP.
|
||||
push ebx
|
||||
push ebp
|
||||
push edi
|
||||
push esi
|
||||
|
||||
; Save Core Stack pointer.
|
||||
mov [ASM_PFX(CoreEsp)], esp
|
||||
|
||||
push dword [ASM_PFX(gRing3EntryPoint)]
|
||||
push dword [ASM_PFX(gRing3CallStackTop)]
|
||||
|
||||
SetRing3DataSegmentSelectors
|
||||
|
||||
; Prepare SYSEXIT arguments.
|
||||
pop ecx
|
||||
pop edx
|
||||
mov eax, [esp + 4 * 5] ; Data
|
||||
|
||||
; Switch to User Stack.
|
||||
mov ebp, ecx
|
||||
|
||||
; Pass control to user image
|
||||
sti
|
||||
sysexit
|
||||
|
||||
coreReturnAddress:
|
||||
mov esp, [ASM_PFX(CoreEsp)]
|
||||
pop esi
|
||||
pop edi
|
||||
pop ebp
|
||||
pop ebx
|
||||
|
||||
call ASM_PFX(DisableSMAP)
|
||||
mov eax, [edx + 2 * 4] ; User Argument 1
|
||||
push eax
|
||||
call ASM_PFX(EnableSMAP)
|
||||
pop eax
|
||||
|
||||
sti
|
||||
ret
|
||||
|
||||
SECTION .data
|
||||
ASM_PFX(CoreEsp):
|
||||
resd 1
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
#include <Register/Intel/ArchitecturalMsr.h>
|
||||
|
||||
extern ASM_PFX(CallBootService)
|
||||
extern ASM_PFX(gCoreSysCallStackTop)
|
||||
extern ASM_PFX(gRing3CallStackTop)
|
||||
extern ASM_PFX(gRing3EntryPoint)
|
||||
|
||||
extern ASM_PFX(AsmReadMsr64)
|
||||
|
||||
DEFAULT REL
|
||||
SECTION .text
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; DisableSMAP (
|
||||
; VOID
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(DisableSMAP)
|
||||
ASM_PFX(DisableSMAP):
|
||||
pushfd
|
||||
pop eax
|
||||
or eax, 0x40000 ; Set AC (bit 18)
|
||||
push eax
|
||||
popfd
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; EnableSMAP (
|
||||
; VOID
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(EnableSMAP)
|
||||
ASM_PFX(EnableSMAP):
|
||||
pushfd
|
||||
pop eax
|
||||
and eax, ~0x40000 ; Clear AC (bit 18)
|
||||
push eax
|
||||
popfd
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CallInstallMultipleProtocolInterfaces (
|
||||
; IN EFI_HANDLE *Handle,
|
||||
; IN VOID **ArgList,
|
||||
; IN UINT32 ArgListSize,
|
||||
; IN VOID *Function
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CallInstallMultipleProtocolInterfaces)
|
||||
ASM_PFX(CallInstallMultipleProtocolInterfaces):
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
; Prepare stack for call.
|
||||
mov eax, [ebp + 3 * 4] ; eax = ArgList
|
||||
mov ecx, [ebp + 4 * 4] ; ecx = ArgListSize
|
||||
lea eax, [eax + ecx * 4]
|
||||
copy:
|
||||
sub eax, 4
|
||||
push dword [eax]
|
||||
sub ecx, 1
|
||||
jnz copy
|
||||
push dword [ebp + 2 * 4]
|
||||
|
||||
call [ebp + 5 * 4]
|
||||
|
||||
; Step over Function arguments.
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
|
||||
ret
|
||||
|
||||
%macro SetRing3DataSegmentSelectors 0
|
||||
push dword MSR_IA32_SYSENTER_CS
|
||||
call ASM_PFX(AsmReadMsr64)
|
||||
; eax = RING0_CODE32_SEL
|
||||
add eax, 24 ; GDT: RING0_CODE32, RING0_DATA32, RING3_CODE32, RING3_DATA32
|
||||
or eax, 3 ; RPL = 3
|
||||
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
pop eax
|
||||
%endmacro
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CoreBootServices (
|
||||
; IN UINT8 Type,
|
||||
; ...
|
||||
; );
|
||||
;
|
||||
; (eax) User return address.
|
||||
; (ecx) Type.
|
||||
; (edx) User Stack Pointer.
|
||||
;
|
||||
; (On User Stack) Argument 1, 2, ...
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CoreBootServices)
|
||||
ASM_PFX(CoreBootServices):
|
||||
; Save User return address and Stack pointers.
|
||||
push edx
|
||||
push ebp
|
||||
push eax
|
||||
|
||||
; Switch from User to Core data segment selectors.
|
||||
mov ax, ss
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
; Special case for SysCallReturnToCore.
|
||||
cmp ecx, 0
|
||||
je coreReturnAddress
|
||||
|
||||
; Prepare CallBootService arguments.
|
||||
call ASM_PFX(DisableSMAP)
|
||||
mov eax, [edx + 4 * 4] ; User Argument 3
|
||||
push eax
|
||||
mov eax, [edx + 3 * 4] ; User Argument 2
|
||||
push eax
|
||||
mov eax, [edx + 2 * 4] ; User Argument 1
|
||||
push eax
|
||||
call ASM_PFX(EnableSMAP)
|
||||
mov ebp, esp
|
||||
push edx
|
||||
push ebp
|
||||
push ecx
|
||||
|
||||
sti
|
||||
call ASM_PFX(CallBootService)
|
||||
push eax
|
||||
cli
|
||||
|
||||
SetRing3DataSegmentSelectors
|
||||
|
||||
pop eax
|
||||
|
||||
; Step over User Arguments [1..3] and CallBootService input.
|
||||
add esp, 4*6
|
||||
|
||||
; Prepare SYSEXIT arguments.
|
||||
pop edx ; User return address.
|
||||
pop ebp
|
||||
pop ecx ; User Stack Pointer.
|
||||
|
||||
sti
|
||||
sysexit
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CallRing3 (
|
||||
; IN RING3_CALL_DATA *Data
|
||||
; );
|
||||
;
|
||||
; (On User Stack) Data
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CallRing3)
|
||||
ASM_PFX(CallRing3):
|
||||
cli
|
||||
; Save nonvolatile registers EBX, EBP, EDI, ESI, ESP.
|
||||
push ebx
|
||||
push ebp
|
||||
push edi
|
||||
push esi
|
||||
|
||||
; Save Core Stack pointer.
|
||||
mov [ASM_PFX(CoreEsp)], esp
|
||||
|
||||
push dword [ASM_PFX(gRing3EntryPoint)]
|
||||
push dword [ASM_PFX(gRing3CallStackTop)]
|
||||
|
||||
SetRing3DataSegmentSelectors
|
||||
|
||||
; Prepare SYSEXIT arguments.
|
||||
pop ecx
|
||||
pop edx
|
||||
mov eax, [esp + 4 * 5] ; Data
|
||||
|
||||
; Switch to User Stack.
|
||||
mov ebp, ecx
|
||||
|
||||
; Pass control to user image
|
||||
sti
|
||||
sysexit
|
||||
|
||||
coreReturnAddress:
|
||||
mov esp, [ASM_PFX(CoreEsp)]
|
||||
pop esi
|
||||
pop edi
|
||||
pop ebp
|
||||
pop ebx
|
||||
|
||||
call ASM_PFX(DisableSMAP)
|
||||
mov eax, [edx + 2 * 4] ; User Argument 1
|
||||
push eax
|
||||
call ASM_PFX(EnableSMAP)
|
||||
pop eax
|
||||
|
||||
sti
|
||||
ret
|
||||
|
||||
SECTION .data
|
||||
ASM_PFX(CoreEsp):
|
||||
resd 1
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
#include <Register/Intel/ArchitecturalMsr.h>
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
)
|
||||
{
|
||||
UINT64 Msr;
|
||||
IA32_CR4 Cr4;
|
||||
IA32_EFLAGS32 Eflags;
|
||||
UINT32 Ebx;
|
||||
UINT32 Edx;
|
||||
|
||||
Ebx = 0;
|
||||
Edx = 0;
|
||||
|
||||
//
|
||||
// Forbid supervisor-mode accesses to any user-mode pages.
|
||||
//
|
||||
AsmCpuidEx (0x07, 0x0, NULL, &Ebx, NULL, NULL);
|
||||
if (((Ebx & BIT20) != 0) && ((Ebx & BIT7) != 0)) {
|
||||
Cr4.UintN = AsmReadCr4 ();
|
||||
Cr4.Bits.SMAP = 1;
|
||||
Cr4.Bits.SMEP = 1;
|
||||
AsmWriteCr4 (Cr4.UintN);
|
||||
|
||||
Eflags.UintN = AsmReadEflags ();
|
||||
Eflags.Bits.AC = 0;
|
||||
AsmWriteEflags (Eflags.UintN);
|
||||
}
|
||||
|
||||
//
|
||||
// SYSENTER and SYSEXIT must be supported.
|
||||
//
|
||||
AsmCpuidEx (0x01, 0x0, NULL, NULL, NULL, &Edx);
|
||||
if ((Edx & BIT11) == 0) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: SYSENTER and SYSEXIT are not supported.\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_EIP and
|
||||
// MSR_IA32_SYSENTER_ESP for SYSENTER and SYSEXIT.
|
||||
//
|
||||
Msr = RING0_CODE32_SEL;
|
||||
AsmWriteMsr64 (MSR_IA32_SYSENTER_CS, Msr);
|
||||
|
||||
Msr = (UINT64)(UINTN)CoreBootServices;
|
||||
AsmWriteMsr64 (MSR_IA32_SYSENTER_EIP, Msr);
|
||||
|
||||
Msr = (UINT64)(UINTN)gCoreSysCallStackTop;
|
||||
AsmWriteMsr64 (MSR_IA32_SYSENTER_ESP, Msr);
|
||||
}
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
#include <Register/Intel/ArchitecturalMsr.h>
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
)
|
||||
{
|
||||
UINT64 Msr;
|
||||
IA32_CR4 Cr4;
|
||||
IA32_EFLAGS32 Eflags;
|
||||
UINT32 Ebx;
|
||||
UINT32 Edx;
|
||||
|
||||
Ebx = 0;
|
||||
Edx = 0;
|
||||
|
||||
//
|
||||
// Forbid supervisor-mode accesses to any user-mode pages.
|
||||
//
|
||||
AsmCpuidEx (0x07, 0x0, NULL, &Ebx, NULL, NULL);
|
||||
if (((Ebx & BIT20) != 0) && ((Ebx & BIT7) != 0)) {
|
||||
Cr4.UintN = AsmReadCr4 ();
|
||||
Cr4.Bits.SMAP = 1;
|
||||
Cr4.Bits.SMEP = 1;
|
||||
AsmWriteCr4 (Cr4.UintN);
|
||||
|
||||
Eflags.UintN = AsmReadEflags ();
|
||||
Eflags.Bits.AC = 0;
|
||||
AsmWriteEflags (Eflags.UintN);
|
||||
}
|
||||
|
||||
//
|
||||
// SYSENTER and SYSEXIT must be supported.
|
||||
//
|
||||
AsmCpuidEx (0x01, 0x0, NULL, NULL, NULL, &Edx);
|
||||
if ((Edx & BIT11) == 0) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: SYSENTER and SYSEXIT are not supported.\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_EIP and
|
||||
// MSR_IA32_SYSENTER_ESP for SYSENTER and SYSEXIT.
|
||||
//
|
||||
Msr = RING0_CODE32_SEL;
|
||||
AsmWriteMsr64 (MSR_IA32_SYSENTER_CS, Msr);
|
||||
|
||||
Msr = (UINT64)(UINTN)CoreBootServices;
|
||||
AsmWriteMsr64 (MSR_IA32_SYSENTER_EIP, Msr);
|
||||
|
||||
Msr = (UINT64)(UINTN)gCoreSysCallStackTop;
|
||||
AsmWriteMsr64 (MSR_IA32_SYSENTER_ESP, Msr);
|
||||
}
|
||||
|
|
|
@ -1,151 +1,151 @@
|
|||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
VOID *gCoreSysCallStackTop;
|
||||
VOID *gCoreSysCallStackBase;
|
||||
VOID *gRing3CallStackTop;
|
||||
VOID *gRing3CallStackBase;
|
||||
VOID *gRing3EntryPoint;
|
||||
RING3_DATA *gRing3Data;
|
||||
VOID *gRing3Interfaces;
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeRing3 (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN LOADED_IMAGE_PRIVATE_DATA *Image
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
VOID *TopOfStack;
|
||||
UINTN SizeOfStack;
|
||||
EFI_PHYSICAL_ADDRESS Physical;
|
||||
UINTN Index;
|
||||
EFI_CONFIGURATION_TABLE *Conf;
|
||||
|
||||
//
|
||||
// Set Ring3 EntryPoint and BootServices.
|
||||
//
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
EFI_SIZE_TO_PAGES (sizeof (RING3_DATA)),
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3Data.\n"));
|
||||
return Status;
|
||||
}
|
||||
|
||||
gRing3Data = (RING3_DATA *)(UINTN)Physical;
|
||||
|
||||
CopyMem ((VOID *)gRing3Data, (VOID *)Image->Info.SystemTable, sizeof (EFI_SYSTEM_TABLE));
|
||||
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
EFI_SIZE_TO_PAGES (gRing3Data->SystemTable.NumberOfTableEntries * sizeof (EFI_CONFIGURATION_TABLE)),
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3 ConfigurationTable.\n"));
|
||||
return Status;
|
||||
}
|
||||
|
||||
Conf = (EFI_CONFIGURATION_TABLE *)(UINTN)Physical;
|
||||
|
||||
for (Index = 0; Index < gRing3Data->SystemTable.NumberOfTableEntries; ++Index) {
|
||||
Conf->VendorGuid = gRing3Data->SystemTable.ConfigurationTable[Index].VendorGuid;
|
||||
Conf->VendorTable = gRing3Data->SystemTable.ConfigurationTable[Index].VendorTable;
|
||||
++Conf;
|
||||
}
|
||||
|
||||
gRing3Data->SystemTable.ConfigurationTable = (EFI_CONFIGURATION_TABLE *)(UINTN)Physical;
|
||||
|
||||
//
|
||||
// Initialize DxeRing3 with Supervisor privileges.
|
||||
//
|
||||
ChangeUefiImageRing (&Image->Info, Image->LoadedImageDevicePath, FALSE);
|
||||
|
||||
Status = Image->EntryPoint (ImageHandle, (EFI_SYSTEM_TABLE *)gRing3Data);
|
||||
|
||||
ChangeUefiImageRing (&Image->Info, Image->LoadedImageDevicePath, TRUE);
|
||||
|
||||
gRing3EntryPoint = gRing3Data->EntryPoint;
|
||||
|
||||
gRing3Data->SystemTable.BootServices = gRing3Data->BootServices;
|
||||
gRing3Data->SystemTable.RuntimeServices = gRing3Data->RuntimeServices;
|
||||
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
RING3_INTERFACES_PAGES,
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3Interfaces.\n"));
|
||||
CoreFreePages (
|
||||
(EFI_PHYSICAL_ADDRESS)(UINTN)gRing3Data,
|
||||
EFI_SIZE_TO_PAGES (sizeof (RING3_DATA))
|
||||
);
|
||||
return Status;
|
||||
}
|
||||
|
||||
gRing3Interfaces = (VOID *)(UINTN)Physical;
|
||||
|
||||
SizeOfStack = EFI_SIZE_TO_PAGES (USER_STACK_SIZE) * EFI_PAGE_SIZE;
|
||||
|
||||
//
|
||||
// Allocate 128KB for the Core SysCall Stack.
|
||||
//
|
||||
gCoreSysCallStackBase = AllocatePages (EFI_SIZE_TO_PAGES (USER_STACK_SIZE));
|
||||
ASSERT (gCoreSysCallStackBase != NULL);
|
||||
|
||||
//
|
||||
// Compute the top of the allocated stack. Pre-allocate a UINTN for safety.
|
||||
//
|
||||
TopOfStack = (VOID *)((UINTN)gCoreSysCallStackBase + SizeOfStack - CPU_STACK_ALIGNMENT);
|
||||
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
||||
|
||||
gCoreSysCallStackTop = TopOfStack;
|
||||
|
||||
SetUefiImageMemoryAttributes ((UINTN)gCoreSysCallStackBase, SizeOfStack, EFI_MEMORY_XP);
|
||||
DEBUG ((DEBUG_ERROR, "Core: gCoreSysCallStackTop = %p\n", gCoreSysCallStackTop));
|
||||
|
||||
//
|
||||
// Allocate 128KB for the User Stack.
|
||||
//
|
||||
gRing3CallStackBase = AllocatePages (EFI_SIZE_TO_PAGES (USER_STACK_SIZE));
|
||||
ASSERT (gRing3CallStackBase != NULL);
|
||||
|
||||
//
|
||||
// Compute the top of the allocated stack. Pre-allocate a UINTN for safety.
|
||||
//
|
||||
TopOfStack = (VOID *)((UINTN)gRing3CallStackBase + SizeOfStack - CPU_STACK_ALIGNMENT);
|
||||
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
||||
|
||||
gRing3CallStackTop = TopOfStack;
|
||||
|
||||
SetUefiImageMemoryAttributes ((UINTN)gRing3CallStackBase, SizeOfStack, EFI_MEMORY_XP | EFI_MEMORY_USER);
|
||||
DEBUG ((DEBUG_ERROR, "Core: gRing3CallStackTop = %p\n", gRing3CallStackTop));
|
||||
|
||||
InitializeMsr (
|
||||
gRing3Data->SystemTable.ConfigurationTable,
|
||||
gRing3Data->SystemTable.NumberOfTableEntries
|
||||
);
|
||||
|
||||
return Status;
|
||||
}
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
VOID *gCoreSysCallStackTop;
|
||||
VOID *gCoreSysCallStackBase;
|
||||
VOID *gRing3CallStackTop;
|
||||
VOID *gRing3CallStackBase;
|
||||
VOID *gRing3EntryPoint;
|
||||
RING3_DATA *gRing3Data;
|
||||
VOID *gRing3Interfaces;
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeRing3 (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN LOADED_IMAGE_PRIVATE_DATA *Image
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
VOID *TopOfStack;
|
||||
UINTN SizeOfStack;
|
||||
EFI_PHYSICAL_ADDRESS Physical;
|
||||
UINTN Index;
|
||||
EFI_CONFIGURATION_TABLE *Conf;
|
||||
|
||||
//
|
||||
// Set Ring3 EntryPoint and BootServices.
|
||||
//
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
EFI_SIZE_TO_PAGES (sizeof (RING3_DATA)),
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3Data.\n"));
|
||||
return Status;
|
||||
}
|
||||
|
||||
gRing3Data = (RING3_DATA *)(UINTN)Physical;
|
||||
|
||||
CopyMem ((VOID *)gRing3Data, (VOID *)Image->Info.SystemTable, sizeof (EFI_SYSTEM_TABLE));
|
||||
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
EFI_SIZE_TO_PAGES (gRing3Data->SystemTable.NumberOfTableEntries * sizeof (EFI_CONFIGURATION_TABLE)),
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3 ConfigurationTable.\n"));
|
||||
return Status;
|
||||
}
|
||||
|
||||
Conf = (EFI_CONFIGURATION_TABLE *)(UINTN)Physical;
|
||||
|
||||
for (Index = 0; Index < gRing3Data->SystemTable.NumberOfTableEntries; ++Index) {
|
||||
Conf->VendorGuid = gRing3Data->SystemTable.ConfigurationTable[Index].VendorGuid;
|
||||
Conf->VendorTable = gRing3Data->SystemTable.ConfigurationTable[Index].VendorTable;
|
||||
++Conf;
|
||||
}
|
||||
|
||||
gRing3Data->SystemTable.ConfigurationTable = (EFI_CONFIGURATION_TABLE *)(UINTN)Physical;
|
||||
|
||||
//
|
||||
// Initialize DxeRing3 with Supervisor privileges.
|
||||
//
|
||||
ChangeUefiImageRing (&Image->Info, Image->LoadedImageDevicePath, FALSE);
|
||||
|
||||
Status = Image->EntryPoint (ImageHandle, (EFI_SYSTEM_TABLE *)gRing3Data);
|
||||
|
||||
ChangeUefiImageRing (&Image->Info, Image->LoadedImageDevicePath, TRUE);
|
||||
|
||||
gRing3EntryPoint = gRing3Data->EntryPoint;
|
||||
|
||||
gRing3Data->SystemTable.BootServices = gRing3Data->BootServices;
|
||||
gRing3Data->SystemTable.RuntimeServices = gRing3Data->RuntimeServices;
|
||||
|
||||
Status = CoreAllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiRing3MemoryType,
|
||||
RING3_INTERFACES_PAGES,
|
||||
&Physical
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3Interfaces.\n"));
|
||||
CoreFreePages (
|
||||
(EFI_PHYSICAL_ADDRESS)(UINTN)gRing3Data,
|
||||
EFI_SIZE_TO_PAGES (sizeof (RING3_DATA))
|
||||
);
|
||||
return Status;
|
||||
}
|
||||
|
||||
gRing3Interfaces = (VOID *)(UINTN)Physical;
|
||||
|
||||
SizeOfStack = EFI_SIZE_TO_PAGES (USER_STACK_SIZE) * EFI_PAGE_SIZE;
|
||||
|
||||
//
|
||||
// Allocate 128KB for the Core SysCall Stack.
|
||||
//
|
||||
gCoreSysCallStackBase = AllocatePages (EFI_SIZE_TO_PAGES (USER_STACK_SIZE));
|
||||
ASSERT (gCoreSysCallStackBase != NULL);
|
||||
|
||||
//
|
||||
// Compute the top of the allocated stack. Pre-allocate a UINTN for safety.
|
||||
//
|
||||
TopOfStack = (VOID *)((UINTN)gCoreSysCallStackBase + SizeOfStack - CPU_STACK_ALIGNMENT);
|
||||
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
||||
|
||||
gCoreSysCallStackTop = TopOfStack;
|
||||
|
||||
SetUefiImageMemoryAttributes ((UINTN)gCoreSysCallStackBase, SizeOfStack, EFI_MEMORY_XP);
|
||||
DEBUG ((DEBUG_ERROR, "Core: gCoreSysCallStackTop = %p\n", gCoreSysCallStackTop));
|
||||
|
||||
//
|
||||
// Allocate 128KB for the User Stack.
|
||||
//
|
||||
gRing3CallStackBase = AllocatePages (EFI_SIZE_TO_PAGES (USER_STACK_SIZE));
|
||||
ASSERT (gRing3CallStackBase != NULL);
|
||||
|
||||
//
|
||||
// Compute the top of the allocated stack. Pre-allocate a UINTN for safety.
|
||||
//
|
||||
TopOfStack = (VOID *)((UINTN)gRing3CallStackBase + SizeOfStack - CPU_STACK_ALIGNMENT);
|
||||
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
||||
|
||||
gRing3CallStackTop = TopOfStack;
|
||||
|
||||
SetUefiImageMemoryAttributes ((UINTN)gRing3CallStackBase, SizeOfStack, EFI_MEMORY_XP | EFI_MEMORY_USER);
|
||||
DEBUG ((DEBUG_ERROR, "Core: gRing3CallStackTop = %p\n", gRing3CallStackTop));
|
||||
|
||||
InitializeMsr (
|
||||
gRing3Data->SystemTable.ConfigurationTable,
|
||||
gRing3Data->SystemTable.NumberOfTableEntries
|
||||
);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,48 +1,48 @@
|
|||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include <Protocol/BlockIo.h>
|
||||
#include <Protocol/ComponentName.h>
|
||||
#include <Protocol/DevicePathUtilities.h>
|
||||
#include <Protocol/DiskIo.h>
|
||||
#include <Protocol/UnicodeCollation.h>
|
||||
|
||||
extern EFI_DRIVER_BINDING_PROTOCOL mRing3DriverBindingProtocol;
|
||||
extern EFI_SIMPLE_FILE_SYSTEM_PROTOCOL mRing3SimpleFileSystemProtocol;
|
||||
extern EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *mRing3SimpleFileSystemPointer;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreDriverBindingSupported (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreDriverBindingStart (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreDriverBindingStop (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN UINTN NumberOfChildren,
|
||||
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreOpenVolume (
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
|
||||
OUT EFI_FILE_PROTOCOL **Root
|
||||
);
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include <Protocol/BlockIo.h>
|
||||
#include <Protocol/ComponentName.h>
|
||||
#include <Protocol/DevicePathUtilities.h>
|
||||
#include <Protocol/DiskIo.h>
|
||||
#include <Protocol/UnicodeCollation.h>
|
||||
|
||||
extern EFI_DRIVER_BINDING_PROTOCOL mRing3DriverBindingProtocol;
|
||||
extern EFI_SIMPLE_FILE_SYSTEM_PROTOCOL mRing3SimpleFileSystemProtocol;
|
||||
extern EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *mRing3SimpleFileSystemPointer;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreDriverBindingSupported (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreDriverBindingStart (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreDriverBindingStop (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN UINTN NumberOfChildren,
|
||||
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CoreOpenVolume (
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
|
||||
OUT EFI_FILE_PROTOCOL **Root
|
||||
);
|
||||
|
|
|
@ -1,246 +1,246 @@
|
|||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
#include <Register/Intel/ArchitecturalMsr.h>
|
||||
|
||||
extern ASM_PFX(CallBootService)
|
||||
extern ASM_PFX(gCoreSysCallStackTop)
|
||||
extern ASM_PFX(gRing3CallStackTop)
|
||||
extern ASM_PFX(gRing3EntryPoint)
|
||||
|
||||
DEFAULT REL
|
||||
SECTION .text
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; DisableSMAP (
|
||||
; VOID
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(DisableSMAP)
|
||||
ASM_PFX(DisableSMAP):
|
||||
pushfq
|
||||
pop r10
|
||||
or r10, 0x40000 ; Set AC (bit 18)
|
||||
push r10
|
||||
popfq
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; EnableSMAP (
|
||||
; VOID
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(EnableSMAP)
|
||||
ASM_PFX(EnableSMAP):
|
||||
pushfq
|
||||
pop r10
|
||||
and r10, ~0x40000 ; Clear AC (bit 18)
|
||||
push r10
|
||||
popfq
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CallInstallMultipleProtocolInterfaces (
|
||||
; IN EFI_HANDLE *Handle,
|
||||
; IN VOID **ArgList,
|
||||
; IN UINT32 ArgListSize,
|
||||
; IN VOID *Function
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CallInstallMultipleProtocolInterfaces)
|
||||
ASM_PFX(CallInstallMultipleProtocolInterfaces):
|
||||
push r12
|
||||
|
||||
; Save function input.
|
||||
mov rax, rdx
|
||||
mov r10, r8
|
||||
mov r11, r9
|
||||
|
||||
; Prepare registers for call.
|
||||
mov rdx, [rax]
|
||||
mov r8, [rax + 8]
|
||||
mov r9, [rax + 8*2]
|
||||
|
||||
; Prepare stack for call.
|
||||
lea rax, [rax + r10 * 8]
|
||||
mov r12, r10
|
||||
copy:
|
||||
sub rax, 8
|
||||
push qword [rax]
|
||||
sub r10, 1
|
||||
jnz copy
|
||||
push rcx
|
||||
|
||||
call r11
|
||||
|
||||
; Step over Function arguments.
|
||||
pop rcx
|
||||
lea rsp, [rsp + r12 * 8]
|
||||
|
||||
pop r12
|
||||
|
||||
ret
|
||||
|
||||
%macro SetRing3DataSegmentSelectors 0
|
||||
mov rcx, MSR_IA32_STAR
|
||||
rdmsr
|
||||
shl rdx, 0x20
|
||||
or rax, rdx
|
||||
; rax = ((RING3_CODE64_SEL - 16) << 16 | RING0_CODE64_SEL) << 32
|
||||
shr rax, 48
|
||||
add rax, 8
|
||||
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
%endmacro
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CoreBootServices (
|
||||
; IN UINT8 Type,
|
||||
; ...
|
||||
; );
|
||||
;
|
||||
; (rcx) RIP of the next instruction saved by SYSCALL in SysCall().
|
||||
; (rdx) Argument 1 of the called function.
|
||||
; (r8) Argument 2 of the called function.
|
||||
; (r9) Argument 3 of the called function.
|
||||
; (r10) Type.
|
||||
; (r11) RFLAGS saved by SYSCALL in SysCall().
|
||||
;
|
||||
; (On User Stack) Argument 4, 5, ...
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CoreBootServices)
|
||||
ASM_PFX(CoreBootServices):
|
||||
; Switch from User to Core data segment selectors.
|
||||
mov ax, ss
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
; Special case for SysCallReturnToCore.
|
||||
cmp r10, 0
|
||||
je coreReturnAddress
|
||||
|
||||
; Save User Stack pointers and switch to Core SysCall Stack.
|
||||
mov rax, [ASM_PFX(gCoreSysCallStackTop)]
|
||||
sub rax, 8
|
||||
mov [rax], rsp
|
||||
mov rsp, rax
|
||||
push rbp
|
||||
; Save return address for SYSRET.
|
||||
push rcx
|
||||
; Save User RFLAGS for SYSRET.
|
||||
push r11
|
||||
; Save User Arguments [1..3].
|
||||
push r9
|
||||
push r8
|
||||
push rdx
|
||||
mov rbp, rsp
|
||||
|
||||
; Prepare CallBootService arguments.
|
||||
mov rcx, r10
|
||||
mov rdx, rbp
|
||||
mov r8, [rbp + 8*6]
|
||||
|
||||
sti
|
||||
call ASM_PFX(CallBootService)
|
||||
push rax
|
||||
cli
|
||||
|
||||
SetRing3DataSegmentSelectors
|
||||
|
||||
pop rax
|
||||
|
||||
; Step over Arguments [1..3].
|
||||
add rsp, 8*3
|
||||
|
||||
; Prepare SYSRET arguments.
|
||||
pop r11
|
||||
pop rcx
|
||||
|
||||
; Switch to User Stack.
|
||||
pop rbp
|
||||
pop rsp
|
||||
|
||||
; SYSCALL saves RFLAGS into R11 and the RIP of the next instruction into RCX.
|
||||
o64 sysret
|
||||
; SYSRET copies the value in RCX into RIP and loads RFLAGS from R11.
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CallRing3 (
|
||||
; IN RING3_CALL_DATA *Data
|
||||
; );
|
||||
;
|
||||
; (rcx) Data
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CallRing3)
|
||||
ASM_PFX(CallRing3):
|
||||
pushfq
|
||||
pop r11
|
||||
cli
|
||||
; Save nonvolatile registers RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15.
|
||||
push rbx
|
||||
push rbp
|
||||
push rdi
|
||||
push rsi
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
push r15
|
||||
|
||||
; Save Core Stack pointer.
|
||||
mov [ASM_PFX(CoreRsp)], rsp
|
||||
|
||||
; Save input Arguments.
|
||||
mov r8, [ASM_PFX(gRing3CallStackTop)]
|
||||
mov r9, [ASM_PFX(gRing3EntryPoint)]
|
||||
mov r10, rcx
|
||||
|
||||
SetRing3DataSegmentSelectors
|
||||
|
||||
; Prepare SYSRET arguments.
|
||||
mov rdx, r10
|
||||
mov rcx, r9
|
||||
|
||||
; Switch to User Stack.
|
||||
mov rsp, r8
|
||||
mov rbp, rsp
|
||||
|
||||
; Pass control to user image
|
||||
o64 sysret
|
||||
|
||||
coreReturnAddress:
|
||||
mov rsp, [ASM_PFX(CoreRsp)]
|
||||
pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
pop r12
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop rbp
|
||||
pop rbx
|
||||
|
||||
mov rax, rdx
|
||||
sti
|
||||
ret
|
||||
|
||||
SECTION .data
|
||||
ASM_PFX(CoreRsp):
|
||||
resq 1
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
#include <Register/Intel/ArchitecturalMsr.h>
|
||||
|
||||
extern ASM_PFX(CallBootService)
|
||||
extern ASM_PFX(gCoreSysCallStackTop)
|
||||
extern ASM_PFX(gRing3CallStackTop)
|
||||
extern ASM_PFX(gRing3EntryPoint)
|
||||
|
||||
DEFAULT REL
|
||||
SECTION .text
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; DisableSMAP (
|
||||
; VOID
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(DisableSMAP)
|
||||
ASM_PFX(DisableSMAP):
|
||||
pushfq
|
||||
pop r10
|
||||
or r10, 0x40000 ; Set AC (bit 18)
|
||||
push r10
|
||||
popfq
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VOID
|
||||
; EFIAPI
|
||||
; EnableSMAP (
|
||||
; VOID
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(EnableSMAP)
|
||||
ASM_PFX(EnableSMAP):
|
||||
pushfq
|
||||
pop r10
|
||||
and r10, ~0x40000 ; Clear AC (bit 18)
|
||||
push r10
|
||||
popfq
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CallInstallMultipleProtocolInterfaces (
|
||||
; IN EFI_HANDLE *Handle,
|
||||
; IN VOID **ArgList,
|
||||
; IN UINT32 ArgListSize,
|
||||
; IN VOID *Function
|
||||
; );
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CallInstallMultipleProtocolInterfaces)
|
||||
ASM_PFX(CallInstallMultipleProtocolInterfaces):
|
||||
push r12
|
||||
|
||||
; Save function input.
|
||||
mov rax, rdx
|
||||
mov r10, r8
|
||||
mov r11, r9
|
||||
|
||||
; Prepare registers for call.
|
||||
mov rdx, [rax]
|
||||
mov r8, [rax + 8]
|
||||
mov r9, [rax + 8*2]
|
||||
|
||||
; Prepare stack for call.
|
||||
lea rax, [rax + r10 * 8]
|
||||
mov r12, r10
|
||||
copy:
|
||||
sub rax, 8
|
||||
push qword [rax]
|
||||
sub r10, 1
|
||||
jnz copy
|
||||
push rcx
|
||||
|
||||
call r11
|
||||
|
||||
; Step over Function arguments.
|
||||
pop rcx
|
||||
lea rsp, [rsp + r12 * 8]
|
||||
|
||||
pop r12
|
||||
|
||||
ret
|
||||
|
||||
%macro SetRing3DataSegmentSelectors 0
|
||||
mov rcx, MSR_IA32_STAR
|
||||
rdmsr
|
||||
shl rdx, 0x20
|
||||
or rax, rdx
|
||||
; rax = ((RING3_CODE64_SEL - 16) << 16 | RING0_CODE64_SEL) << 32
|
||||
shr rax, 48
|
||||
add rax, 8
|
||||
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
%endmacro
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CoreBootServices (
|
||||
; IN UINT8 Type,
|
||||
; ...
|
||||
; );
|
||||
;
|
||||
; (rcx) RIP of the next instruction saved by SYSCALL in SysCall().
|
||||
; (rdx) Argument 1 of the called function.
|
||||
; (r8) Argument 2 of the called function.
|
||||
; (r9) Argument 3 of the called function.
|
||||
; (r10) Type.
|
||||
; (r11) RFLAGS saved by SYSCALL in SysCall().
|
||||
;
|
||||
; (On User Stack) Argument 4, 5, ...
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CoreBootServices)
|
||||
ASM_PFX(CoreBootServices):
|
||||
; Switch from User to Core data segment selectors.
|
||||
mov ax, ss
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
; Special case for SysCallReturnToCore.
|
||||
cmp r10, 0
|
||||
je coreReturnAddress
|
||||
|
||||
; Save User Stack pointers and switch to Core SysCall Stack.
|
||||
mov rax, [ASM_PFX(gCoreSysCallStackTop)]
|
||||
sub rax, 8
|
||||
mov [rax], rsp
|
||||
mov rsp, rax
|
||||
push rbp
|
||||
; Save return address for SYSRET.
|
||||
push rcx
|
||||
; Save User RFLAGS for SYSRET.
|
||||
push r11
|
||||
; Save User Arguments [1..3].
|
||||
push r9
|
||||
push r8
|
||||
push rdx
|
||||
mov rbp, rsp
|
||||
|
||||
; Prepare CallBootService arguments.
|
||||
mov rcx, r10
|
||||
mov rdx, rbp
|
||||
mov r8, [rbp + 8*6]
|
||||
|
||||
sti
|
||||
call ASM_PFX(CallBootService)
|
||||
push rax
|
||||
cli
|
||||
|
||||
SetRing3DataSegmentSelectors
|
||||
|
||||
pop rax
|
||||
|
||||
; Step over Arguments [1..3].
|
||||
add rsp, 8*3
|
||||
|
||||
; Prepare SYSRET arguments.
|
||||
pop r11
|
||||
pop rcx
|
||||
|
||||
; Switch to User Stack.
|
||||
pop rbp
|
||||
pop rsp
|
||||
|
||||
; SYSCALL saves RFLAGS into R11 and the RIP of the next instruction into RCX.
|
||||
o64 sysret
|
||||
; SYSRET copies the value in RCX into RIP and loads RFLAGS from R11.
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; EFI_STATUS
|
||||
; EFIAPI
|
||||
; CallRing3 (
|
||||
; IN RING3_CALL_DATA *Data
|
||||
; );
|
||||
;
|
||||
; (rcx) Data
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(CallRing3)
|
||||
ASM_PFX(CallRing3):
|
||||
pushfq
|
||||
pop r11
|
||||
cli
|
||||
; Save nonvolatile registers RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15.
|
||||
push rbx
|
||||
push rbp
|
||||
push rdi
|
||||
push rsi
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
push r15
|
||||
|
||||
; Save Core Stack pointer.
|
||||
mov [ASM_PFX(CoreRsp)], rsp
|
||||
|
||||
; Save input Arguments.
|
||||
mov r8, [ASM_PFX(gRing3CallStackTop)]
|
||||
mov r9, [ASM_PFX(gRing3EntryPoint)]
|
||||
mov r10, rcx
|
||||
|
||||
SetRing3DataSegmentSelectors
|
||||
|
||||
; Prepare SYSRET arguments.
|
||||
mov rdx, r10
|
||||
mov rcx, r9
|
||||
|
||||
; Switch to User Stack.
|
||||
mov rsp, r8
|
||||
mov rbp, rsp
|
||||
|
||||
; Pass control to user image
|
||||
o64 sysret
|
||||
|
||||
coreReturnAddress:
|
||||
mov rsp, [ASM_PFX(CoreRsp)]
|
||||
pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
pop r12
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop rbp
|
||||
pop rbx
|
||||
|
||||
mov rax, rdx
|
||||
sti
|
||||
ret
|
||||
|
||||
SECTION .data
|
||||
ASM_PFX(CoreRsp):
|
||||
resq 1
|
||||
|
|
|
@ -1,70 +1,70 @@
|
|||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
#include <Register/Intel/ArchitecturalMsr.h>
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
)
|
||||
{
|
||||
UINT64 Msr;
|
||||
IA32_CR4 Cr4;
|
||||
IA32_EFLAGS32 Eflags;
|
||||
UINT32 Ebx;
|
||||
UINT32 Edx;
|
||||
MSR_IA32_EFER_REGISTER MsrEfer;
|
||||
|
||||
Ebx = 0;
|
||||
Edx = 0;
|
||||
|
||||
//
|
||||
// Forbid supervisor-mode accesses to any user-mode pages.
|
||||
//
|
||||
AsmCpuidEx (0x07, 0x0, NULL, &Ebx, NULL, NULL);
|
||||
if (((Ebx & BIT20) != 0) && ((Ebx & BIT7) != 0)) {
|
||||
Cr4.UintN = AsmReadCr4 ();
|
||||
Cr4.Bits.SMAP = 1;
|
||||
Cr4.Bits.SMEP = 1;
|
||||
AsmWriteCr4 (Cr4.UintN);
|
||||
|
||||
Eflags.UintN = AsmReadEflags ();
|
||||
Eflags.Bits.AC = 0;
|
||||
AsmWriteEflags (Eflags.UintN);
|
||||
}
|
||||
|
||||
//
|
||||
// Enable SYSCALL and SYSRET.
|
||||
//
|
||||
AsmCpuidEx (0x80000001, 0x0, NULL, NULL, NULL, &Edx);
|
||||
if ((Edx & BIT11) != 0) {
|
||||
MsrEfer.Uint64 = AsmReadMsr64 (MSR_IA32_EFER);
|
||||
MsrEfer.Bits.SCE = 1;
|
||||
AsmWriteMsr64 (MSR_IA32_EFER, MsrEfer.Uint64);
|
||||
} else {
|
||||
DEBUG ((DEBUG_ERROR, "Core: SYSCALL and SYSRET are not supported.\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize MSR_IA32_STAR, MSR_IA32_LSTAR and MSR_IA32_FMASK for SYSCALL and SYSRET.
|
||||
//
|
||||
Msr = (((((UINT64)RING3_CODE64_SEL - 16) | 3) << 16) | (UINT64)RING0_CODE64_SEL) << 32;
|
||||
AsmWriteMsr64 (MSR_IA32_STAR, Msr);
|
||||
|
||||
Msr = (UINT64)(UINTN)CoreBootServices;
|
||||
AsmWriteMsr64 (MSR_IA32_LSTAR, Msr);
|
||||
//
|
||||
// Disable maskable interrupts at SYSCALL.
|
||||
//
|
||||
Msr = (UINT64)BIT9;
|
||||
AsmWriteMsr64 (MSR_IA32_FMASK, Msr);
|
||||
}
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2024, Mikhail Krichanov. All rights reserved.
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
**/
|
||||
|
||||
#include "DxeMain.h"
|
||||
|
||||
#include <Register/Intel/ArchitecturalMsr.h>
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeMsr (
|
||||
IN OUT EFI_CONFIGURATION_TABLE *Table,
|
||||
IN UINTN NumberOfEntries
|
||||
)
|
||||
{
|
||||
UINT64 Msr;
|
||||
IA32_CR4 Cr4;
|
||||
IA32_EFLAGS32 Eflags;
|
||||
UINT32 Ebx;
|
||||
UINT32 Edx;
|
||||
MSR_IA32_EFER_REGISTER MsrEfer;
|
||||
|
||||
Ebx = 0;
|
||||
Edx = 0;
|
||||
|
||||
//
|
||||
// Forbid supervisor-mode accesses to any user-mode pages.
|
||||
//
|
||||
AsmCpuidEx (0x07, 0x0, NULL, &Ebx, NULL, NULL);
|
||||
if (((Ebx & BIT20) != 0) && ((Ebx & BIT7) != 0)) {
|
||||
Cr4.UintN = AsmReadCr4 ();
|
||||
Cr4.Bits.SMAP = 1;
|
||||
Cr4.Bits.SMEP = 1;
|
||||
AsmWriteCr4 (Cr4.UintN);
|
||||
|
||||
Eflags.UintN = AsmReadEflags ();
|
||||
Eflags.Bits.AC = 0;
|
||||
AsmWriteEflags (Eflags.UintN);
|
||||
}
|
||||
|
||||
//
|
||||
// Enable SYSCALL and SYSRET.
|
||||
//
|
||||
AsmCpuidEx (0x80000001, 0x0, NULL, NULL, NULL, &Edx);
|
||||
if ((Edx & BIT11) != 0) {
|
||||
MsrEfer.Uint64 = AsmReadMsr64 (MSR_IA32_EFER);
|
||||
MsrEfer.Bits.SCE = 1;
|
||||
AsmWriteMsr64 (MSR_IA32_EFER, MsrEfer.Uint64);
|
||||
} else {
|
||||
DEBUG ((DEBUG_ERROR, "Core: SYSCALL and SYSRET are not supported.\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize MSR_IA32_STAR, MSR_IA32_LSTAR and MSR_IA32_FMASK for SYSCALL and SYSRET.
|
||||
//
|
||||
Msr = (((((UINT64)RING3_CODE64_SEL - 16) | 3) << 16) | (UINT64)RING0_CODE64_SEL) << 32;
|
||||
AsmWriteMsr64 (MSR_IA32_STAR, Msr);
|
||||
|
||||
Msr = (UINT64)(UINTN)CoreBootServices;
|
||||
AsmWriteMsr64 (MSR_IA32_LSTAR, Msr);
|
||||
//
|
||||
// Disable maskable interrupts at SYSCALL.
|
||||
//
|
||||
Msr = (UINT64)BIT9;
|
||||
AsmWriteMsr64 (MSR_IA32_FMASK, Msr);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue