Skip to content

Commit

Permalink
Ring3: Refactored out FunctionAddress from API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Krichanov committed Feb 5, 2024
1 parent 1a32743 commit 44cd3c5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
1 change: 0 additions & 1 deletion MdeModulePkg/Core/Dxe/DxeMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -2821,7 +2821,6 @@ UINTN
EFIAPI
CoreBootServices (
IN UINT8 Type,
IN UINTN FunctionAddress,
...
);

Expand Down
16 changes: 8 additions & 8 deletions MdeModulePkg/Core/Dxe/SysCall/BootServices.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ UINTN
EFIAPI
CallBootService (
IN UINT8 Type,
IN VOID **FunctionAddress,
IN UINTN CoreRbp,
IN UINTN UserRsp
)
Expand All @@ -52,11 +51,12 @@ CallBootService (

// Stack:
// rcx - Rip for SYSCALL
// r8 - Argument 1
// rdx - Argument 1
// rbp - User Rbp
// r9 - Argument 2
// r8 - Argument 2
// r11 - User data segment selector <- CoreRbp
// rsp - User Rsp
// r9 - Argument 3
switch (Type) {
case SysCallLocateProtocol:
DisableSMAP ();
Expand Down Expand Up @@ -87,7 +87,7 @@ CallBootService (
}

DisableSMAP ();
*(UINTN *)(*((UINTN *)UserRsp + 5)) = (UINTN)Pointer;
*(UINTN *)(*((UINTN *)CoreRbp - 2)) = (UINTN)Pointer;
EnableSMAP ();

FreePool (CoreProtocol);
Expand All @@ -97,9 +97,9 @@ CallBootService (
case SysCallOpenProtocol:
DisableSMAP ();
CoreProtocol = AllocateCopyPool (sizeof (EFI_GUID), (VOID *)*((UINTN *)CoreRbp + 1));
Arg4 = (VOID *)*((UINTN *)UserRsp + 6);
Arg5 = (VOID *)*((UINTN *)UserRsp + 7);
Arg6 = (UINT32)*((UINTN *)UserRsp + 8);
Arg4 = (VOID *)*((UINTN *)UserRsp + 5);
Arg5 = (VOID *)*((UINTN *)UserRsp + 6);
Arg6 = (UINT32)*((UINTN *)UserRsp + 7);
EnableSMAP ();
if (CoreProtocol == NULL) {
DEBUG ((DEBUG_ERROR, "Ring0: Failed to allocate core copy of the Protocol variable.\n"));
Expand Down Expand Up @@ -129,7 +129,7 @@ CallBootService (
}

DisableSMAP ();
*(UINTN *)(*((UINTN *)UserRsp + 5)) = (UINTN)Pointer;
*(UINTN *)(*((UINTN *)CoreRbp - 2)) = (UINTN)Pointer;
EnableSMAP ();

FreePool (CoreProtocol);
Expand Down
19 changes: 10 additions & 9 deletions MdeModulePkg/Core/Dxe/SysCall/X64/CoreBootServices.nasm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern ASM_PFX(gCoreSysCallStackTop)
; Prepare SYSRET arguments.
mov rcx, [rbp + 8*4]
pop rdx
pop rdx

; Switch from Core to User data segment selectors.
pop r11
Expand Down Expand Up @@ -61,17 +62,16 @@ ASM_PFX(EnableSMAP):
; EFIAPI
; CoreBootServices (
; IN UINT8 Type,
; IN UINTN FunctionAddress,
; ...
; );
;
; (rcx) RIP of the next instruction saved by SYSCALL in SysCall().
; (rdx) FunctionAddress.
; (r8) Argument 1 of the called function.
; (r9) Argument 2 of the called function.
; (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 stack Argument 3, 4, ...
;On stack Argument 4, 5, ...
;------------------------------------------------------------------------------
global ASM_PFX(CoreBootServices)
ASM_PFX(CoreBootServices):
Expand All @@ -92,21 +92,22 @@ ASM_PFX(CoreBootServices):
mov [rax], rcx
mov rcx, r10
sub rax, 8
mov [rax], r8
mov [rax], rdx
sub rax, 8
mov [rax], rbp
sub rax, 8
mov [rax], r9
mov [rax], r8
; Save User data segment selector on Core SysCall Stack.
sub rax, 8
mov [rax], r11

mov r9, rsp
mov r8, rsp

mov rsp, rax

mov rbp, rsp
mov r8, rbp
mov rdx, rbp
push r8
push r9

call ASM_PFX(CallBootService)
Expand Down
1 change: 0 additions & 1 deletion MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ UINTN
EFIAPI
SysCall (
IN UINT8 Type,
IN UINTN FunctionAddress,
...
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ Ring3OpenProtocol (

Status = (EFI_STATUS)SysCall (
SysCallOpenProtocol,
0,
CoreUserHandle,
Protocol,
Interface,
Expand Down Expand Up @@ -531,7 +530,6 @@ Ring3LocateProtocol (

Status = (EFI_STATUS)SysCall (
SysCallLocateProtocol,
0,
Protocol,
CoreRegistration,
Interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@
[LibraryClasses]
BaseMemoryLib
DebugLib

[Protocols]
gEfiDevicePathUtilitiesProtocolGuid ## SOMETIMES_CONSUMES
gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
; EFIAPI
; SysCall (
; IN UINT8 Type,
; IN UINTN FunctionAddress,
; ...
; );
;------------------------------------------------------------------------------
Expand Down

0 comments on commit 44cd3c5

Please sign in to comment.