Skip to content

Commit

Permalink
Ring3: Defined CallRing3() for ARM.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Krichanov committed Jul 5, 2024
1 parent 518e5f1 commit be341ea
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
12 changes: 6 additions & 6 deletions MdeModulePkg/Core/Dxe/DxeRing3/ARM/SysCall.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <AsmMacroIoLib.h>

.extern ASM_PFX(Ring3Call)

//------------------------------------------------------------------------------
// EFI_STATUS
// EFIAPI
Expand All @@ -14,8 +16,8 @@
// );
//------------------------------------------------------------------------------
ASM_FUNC(SysCall)

bx LR
svc #0
bx LR

//------------------------------------------------------------------------------
// VOID
Expand All @@ -24,9 +26,7 @@ ASM_FUNC(SysCall)
// IN RING3_CALL_DATA *Data
// );
//
// (rcx) RIP of Ring3EntryPoint saved for SYSRET in CallRing3().
// (rdx) Data
// (r0) Data
//------------------------------------------------------------------------------
ASM_FUNC(Ring3EntryPoint)

bx LR
b ASM_PFX(Ring3Call)
2 changes: 1 addition & 1 deletion MdeModulePkg/Core/Dxe/SysCall/AARCH64/CoreBootServices.S
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ASM_FUNC(ArmCallRing3)
// Prepare Ring3 SP and EntryPoint.
msr sp_el0, x1
msr elr_el1, x2
// Save Core SP and switch to Ring3Call Stack.
// Save Core SP and switch to CoreSysCall Stack.
mov x5, sp
str x5, [x4]
mov sp, x3
Expand Down
41 changes: 38 additions & 3 deletions MdeModulePkg/Core/Dxe/SysCall/ARM/CoreBootServices.S
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,45 @@ ASM_FUNC(CoreBootServices)
// IN RING3_CALL_DATA *Data
// );
//
// (rcx) Data
// (r0) Data
// (r1) gRing3CallStackTop
// (r2) gRing3EntryPoint
// (r3) gCoreSysCallStackTop
//
// (On Core Stack) &CoreSp
//------------------------------------------------------------------------------
ASM_FUNC(CallRing3)
bx LR
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
orr R5, R4, #0x80
msr CPSR_c, R5

// 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
Expand Down
31 changes: 28 additions & 3 deletions MdeModulePkg/Core/Dxe/SysCall/ARM/InitializeMsr.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@

#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
ArmSetPan (
Expand All @@ -35,7 +47,7 @@ InitializeMsr (
ArmSetPan ();
} else {
DEBUG ((DEBUG_ERROR, "Core: Failed to initialize MSRs for Ring3.\n"));
ASSERT (FALSE);
// ASSERT (FALSE);
}
}

Expand All @@ -45,7 +57,9 @@ DisableSMAP (
VOID
)
{
ArmClearPan ();
if (ArmHasPan ()) {
ArmClearPan ();
}
}

VOID
Expand All @@ -54,5 +68,16 @@ EnableSMAP (
VOID
)
{
ArmSetPan ();
if (ArmHasPan ()) {
ArmSetPan ();
}
}

EFI_STATUS
EFIAPI
CallRing3 (
IN RING3_CALL_DATA *Data
)
{
return ArmCallRing3 (Data, gRing3CallStackTop, gRing3EntryPoint, gCoreSysCallStackTop, &mCoreSp);
}

0 comments on commit be341ea

Please sign in to comment.