mirror of
https://github.com/edk2-porting/edk2-msm
synced 2025-06-02 12:50:50 +00:00
140 lines
3.8 KiB
C
Executable File
140 lines
3.8 KiB
C
Executable File
// Pi.c: Entry point for SEC(Security).
|
|
|
|
#include <PiPei.h>
|
|
#include <Pi/PiBootMode.h>
|
|
|
|
#include <Library/PrePiLib.h>
|
|
#include <Library/PrintLib.h>
|
|
#include <Library/PrePiHobListPointerLib.h>
|
|
#include <Library/CacheMaintenanceLib.h>
|
|
#include <Library/PlatformPrePiLib.h>
|
|
|
|
#include <Ppi/GuidedSectionExtraction.h>
|
|
|
|
#include "Pi.h"
|
|
|
|
#define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) ||\
|
|
((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= FixedPcdGet64 (PcdSystemMemoryBase)))
|
|
|
|
UINT64 mSystemMemoryEnd = FixedPcdGet64 (PcdSystemMemoryBase) +
|
|
FixedPcdGet64 (PcdSystemMemorySize) - 1;
|
|
|
|
VOID EFIAPI ProcessLibraryConstructorList(VOID);
|
|
|
|
VOID
|
|
PrePiMain(
|
|
IN VOID *StackBase,
|
|
IN UINTN StackSize
|
|
)
|
|
{
|
|
|
|
EFI_HOB_HANDOFF_INFO_TABLE *HobList;
|
|
EFI_STATUS Status;
|
|
|
|
UINTN MemoryBase = 0;
|
|
UINTN MemorySize = 0;
|
|
UINTN UefiMemoryBase = 0;
|
|
UINTN UefiMemorySize = 0;
|
|
|
|
// Architecture-specific initialization
|
|
// Enable Floating Point
|
|
ArmEnableVFP();
|
|
|
|
if (ArmReadCurrentEL() == AARCH64_EL2) {
|
|
// Trap General Exceptions. All exceptions that would be routed to EL1 are routed to EL2
|
|
ArmWriteHcr(ARM_HCR_TGE);
|
|
|
|
/* Enable Timer access for non-secure EL1 and EL0
|
|
The cnthctl_el2 register bits are architecturally
|
|
UNKNOWN on reset.
|
|
Disable event stream as it is not in use at this stage
|
|
*/
|
|
ArmWriteCntHctl(CNTHCTL_EL2_EL1PCTEN | CNTHCTL_EL2_EL1PCEN);
|
|
}
|
|
|
|
/* Enable program flow prediction, if supported */
|
|
ArmEnableBranchPrediction();
|
|
|
|
// Declare UEFI region
|
|
MemoryBase = FixedPcdGet32(PcdSystemMemoryBase);
|
|
MemorySize = FixedPcdGet32(PcdSystemMemorySize);
|
|
UefiMemoryBase = FixedPcdGet32(PcdUefiMemPoolBase);
|
|
UefiMemorySize = FixedPcdGet32(PcdUefiMemPoolSize);
|
|
StackBase = (VOID *)(UefiMemoryBase + UefiMemorySize - StackSize);
|
|
|
|
DEBUG(
|
|
(EFI_D_INFO | EFI_D_LOAD,
|
|
"UEFI Memory Base = 0x%llx, Size = 0x%llx \n"
|
|
"Stack Base = 0x%llx, Stack Size = 0x%llx \n",
|
|
UefiMemoryBase, UefiMemorySize, StackBase, StackSize));
|
|
|
|
// Set up HOB
|
|
HobList = HobConstructor(
|
|
(VOID *)UefiMemoryBase, UefiMemorySize, (VOID *)UefiMemoryBase,
|
|
StackBase);
|
|
|
|
PrePeiSetHobList (HobList);
|
|
|
|
// Invalidate cache
|
|
InvalidateDataCacheRange(
|
|
(VOID *)(UINTN)PcdGet64(PcdFdBaseAddress), PcdGet32(PcdFdSize));
|
|
|
|
// Initialize MMU
|
|
Status = MemoryPeim(UefiMemoryBase, UefiMemorySize);
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
// Add HOBs
|
|
BuildStackHob ((UINTN)StackBase, StackSize);
|
|
|
|
// TODO: Call CpuPei as a library
|
|
BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));
|
|
|
|
// Set the Boot Mode
|
|
SetBootMode (BOOT_WITH_DEFAULT_SETTINGS);
|
|
|
|
// Initialize Platform HOBs (CpuHob and FvHob)
|
|
DEBUG((EFI_D_INFO, "PlatformPeim In \n"));
|
|
Status = PlatformPeim();
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
// Now, the HOB List has been initialized, we can register performance information
|
|
// PERF_START (NULL, "PEI", NULL, StartTimeStamp);
|
|
|
|
// SEC phase needs to run library constructors by hand.
|
|
ProcessLibraryConstructorList();
|
|
|
|
// Assume the FV that contains the SEC (our code) also contains a compressed FV.
|
|
DEBUG((EFI_D_INFO, "DecompressFirstFv In \n"));
|
|
Status = DecompressFirstFv();
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
// Load the DXE Core and transfer control to it
|
|
DEBUG((EFI_D_INFO, "LoadDxeCoreFromFv In \n"));
|
|
Status = LoadDxeCoreFromFv(NULL, 0);
|
|
ASSERT_EFI_ERROR (Status);
|
|
}
|
|
|
|
VOID
|
|
CEntryPoint(
|
|
IN VOID *StackBase,
|
|
IN UINTN StackSize
|
|
)
|
|
{
|
|
// Do platform specific initialization here
|
|
PlatformInitialize();
|
|
|
|
// Goto primary Main.
|
|
PrePiMain(StackBase, StackSize);
|
|
|
|
// DXE Core should always load and never return
|
|
ASSERT(FALSE);
|
|
}
|
|
|
|
VOID
|
|
SecondaryCEntryPoint(
|
|
IN UINTN MpId
|
|
)
|
|
{
|
|
// We must never get into this function on UniCore system
|
|
ASSERT(FALSE);
|
|
} |