2011-07-01 13:09:00 +02:00
|
|
|
/** @file
|
|
|
|
*
|
2012-05-02 21:49:35 +02:00
|
|
|
* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
|
2011-07-01 13:09:00 +02:00
|
|
|
*
|
|
|
|
* This program and the accompanying materials
|
|
|
|
* are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
* which accompanies this distribution. The full text of the license may be found at
|
|
|
|
* http://opensource.org/licenses/bsd-license.php
|
|
|
|
*
|
|
|
|
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <PiPei.h>
|
|
|
|
|
|
|
|
#include <Library/DebugAgentLib.h>
|
|
|
|
#include <Library/PrePiLib.h>
|
|
|
|
#include <Library/PrintLib.h>
|
|
|
|
#include <Library/PeCoffGetEntryPointLib.h>
|
2011-08-18 13:17:09 +02:00
|
|
|
#include <Library/PrePiHobListPointerLib.h>
|
2011-07-01 13:09:00 +02:00
|
|
|
#include <Library/TimerLib.h>
|
|
|
|
#include <Library/PerformanceLib.h>
|
|
|
|
|
|
|
|
#include <Ppi/GuidedSectionExtraction.h>
|
|
|
|
#include <Guid/LzmaDecompress.h>
|
2011-09-23 01:11:03 +02:00
|
|
|
#include <Guid/ArmGlobalVariableHob.h>
|
2011-07-01 13:09:00 +02:00
|
|
|
|
|
|
|
#include "PrePi.h"
|
|
|
|
#include "LzmaDecompress.h"
|
|
|
|
|
2011-11-02 00:41:52 +01:00
|
|
|
#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \
|
2011-09-23 01:11:03 +02:00
|
|
|
((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet32 (PcdSystemMemoryBase)))
|
|
|
|
|
|
|
|
// Not used when PrePi in run in XIP mode
|
|
|
|
UINTN mGlobalVariableBase = 0;
|
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
VOID
|
|
|
|
PrePiCommonExceptionEntry (
|
|
|
|
IN UINT32 Entry,
|
|
|
|
IN UINT32 LR
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ExtractGuidedSectionLibConstructor (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
LzmaDecompressLibConstructor (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
2011-09-23 01:11:03 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
BuildGlobalVariableHob (
|
|
|
|
IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,
|
|
|
|
IN UINT32 GlobalVariableSize
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ARM_HOB_GLOBAL_VARIABLE *Hob;
|
|
|
|
|
|
|
|
Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));
|
|
|
|
ASSERT(Hob != NULL);
|
|
|
|
|
|
|
|
CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);
|
|
|
|
Hob->GlobalVariableBase = GlobalVariableBase;
|
|
|
|
Hob->GlobalVariableSize = GlobalVariableSize;
|
|
|
|
}
|
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
VOID
|
|
|
|
PrePiMain (
|
|
|
|
IN UINTN UefiMemoryBase,
|
2011-09-23 01:07:55 +02:00
|
|
|
IN UINTN StacksBase,
|
|
|
|
IN UINTN GlobalVariableBase,
|
2011-07-01 13:09:00 +02:00
|
|
|
IN UINT64 StartTimeStamp
|
|
|
|
)
|
|
|
|
{
|
2011-08-18 13:17:09 +02:00
|
|
|
EFI_HOB_HANDOFF_INFO_TABLE* HobList;
|
2011-07-01 13:09:00 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
CHAR8 Buffer[100];
|
|
|
|
UINTN CharCount;
|
2011-07-06 18:27:21 +02:00
|
|
|
UINTN StacksSize;
|
2011-07-01 13:09:00 +02:00
|
|
|
|
2011-09-23 01:11:03 +02:00
|
|
|
// If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
|
|
|
|
ASSERT (IS_XIP() ||
|
|
|
|
((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&
|
2011-11-02 00:41:52 +01:00
|
|
|
((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));
|
2011-09-23 01:11:03 +02:00
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
// Enable program flow prediction, if supported.
|
|
|
|
ArmEnableBranchPrediction ();
|
|
|
|
|
|
|
|
if (FixedPcdGet32(PcdVFPEnabled)) {
|
|
|
|
ArmEnableVFP();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the Serial Port
|
|
|
|
SerialPortInitialize ();
|
2012-03-26 13:08:32 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",
|
|
|
|
(CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);
|
2011-07-01 13:09:00 +02:00
|
|
|
SerialPortWrite ((UINT8 *) Buffer, CharCount);
|
|
|
|
|
|
|
|
// Initialize the Debug Agent for Source Level Debugging
|
|
|
|
InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
|
|
|
|
SaveAndSetDebugTimerInterrupt (TRUE);
|
2011-07-07 12:52:07 +02:00
|
|
|
|
2011-07-06 18:27:21 +02:00
|
|
|
// Declare the PI/UEFI memory region
|
2011-08-18 13:17:09 +02:00
|
|
|
HobList = HobConstructor (
|
2011-07-01 13:09:00 +02:00
|
|
|
(VOID*)UefiMemoryBase,
|
|
|
|
FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),
|
|
|
|
(VOID*)UefiMemoryBase,
|
2011-07-06 18:27:21 +02:00
|
|
|
(VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks
|
|
|
|
);
|
2011-08-18 13:17:09 +02:00
|
|
|
PrePeiSetHobList (HobList);
|
2011-07-01 13:09:00 +02:00
|
|
|
|
|
|
|
// Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
|
|
|
|
Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2011-07-06 18:27:21 +02:00
|
|
|
// Create the Stacks HOB (reserve the memory for all stacks)
|
2011-11-02 00:41:52 +01:00
|
|
|
if (ArmIsMpCore ()) {
|
|
|
|
StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));
|
|
|
|
} else {
|
|
|
|
StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
|
|
|
|
}
|
2011-07-06 18:27:21 +02:00
|
|
|
BuildStackHob (StacksBase, StacksSize);
|
2011-07-01 13:09:00 +02:00
|
|
|
|
2011-09-23 01:11:03 +02:00
|
|
|
// Declare the Global Variable HOB
|
|
|
|
BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));
|
|
|
|
|
2011-09-23 01:14:01 +02:00
|
|
|
//TODO: Call CpuPei as a library
|
|
|
|
BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
|
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
// Set the Boot Mode
|
|
|
|
SetBootMode (ArmPlatformGetBootMode ());
|
|
|
|
|
|
|
|
// Initialize Platform HOBs (CpuHob and FvHob)
|
|
|
|
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.
|
|
|
|
ExtractGuidedSectionLibConstructor ();
|
|
|
|
LzmaDecompressLibConstructor ();
|
|
|
|
|
|
|
|
// Build HOBs to pass up our version of stuff the DXE Core needs to save space
|
|
|
|
BuildPeCoffLoaderHob ();
|
|
|
|
BuildExtractSectionHob (
|
|
|
|
&gLzmaCustomDecompressGuid,
|
|
|
|
LzmaGuidedSectionGetInfo,
|
|
|
|
LzmaGuidedSectionExtraction
|
|
|
|
);
|
|
|
|
|
|
|
|
// Assume the FV that contains the SEC (our code) also contains a compressed FV.
|
|
|
|
Status = DecompressFirstFv ();
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
// Load the DXE Core and transfer control to it
|
|
|
|
Status = LoadDxeCoreFromFv (NULL, 0);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CEntryPoint (
|
2011-09-23 01:01:13 +02:00
|
|
|
IN UINTN MpId,
|
2011-09-23 01:07:55 +02:00
|
|
|
IN UINTN UefiMemoryBase,
|
|
|
|
IN UINTN StacksBase,
|
|
|
|
IN UINTN GlobalVariableBase
|
2011-07-01 13:09:00 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT64 StartTimeStamp;
|
2011-07-07 12:52:07 +02:00
|
|
|
|
2012-05-02 21:49:35 +02:00
|
|
|
// Initialize the platform specific controllers
|
|
|
|
ArmPlatformInitialize (MpId);
|
|
|
|
|
2011-09-23 01:01:13 +02:00
|
|
|
if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {
|
2011-07-01 13:09:00 +02:00
|
|
|
// Initialize the Timer Library to setup the Timer HW controller
|
|
|
|
TimerConstructor ();
|
|
|
|
// We cannot call yet the PerformanceLib because the HOB List has not been initialized
|
|
|
|
StartTimeStamp = GetPerformanceCounter ();
|
2011-07-07 12:52:07 +02:00
|
|
|
} else {
|
|
|
|
StartTimeStamp = 0;
|
2011-07-01 13:09:00 +02:00
|
|
|
}
|
|
|
|
|
2011-07-06 18:27:21 +02:00
|
|
|
// Clean Data cache
|
|
|
|
ArmCleanInvalidateDataCache ();
|
2011-07-01 13:09:00 +02:00
|
|
|
|
2011-07-06 18:27:21 +02:00
|
|
|
// Invalidate instruction cache
|
|
|
|
ArmInvalidateInstructionCache ();
|
2011-07-01 13:09:00 +02:00
|
|
|
|
|
|
|
//TODO:Drain Write Buffer
|
|
|
|
|
|
|
|
// Enable Instruction & Data caches
|
2011-07-06 18:27:21 +02:00
|
|
|
ArmEnableDataCache ();
|
|
|
|
ArmEnableInstructionCache ();
|
2011-07-01 13:09:00 +02:00
|
|
|
|
2011-11-02 00:41:52 +01:00
|
|
|
// Define the Global Variable region when we are not running in XIP
|
|
|
|
if (!IS_XIP()) {
|
|
|
|
if (IS_PRIMARY_CORE(MpId)) {
|
|
|
|
mGlobalVariableBase = GlobalVariableBase;
|
2011-11-16 13:53:25 +01:00
|
|
|
if (ArmIsMpCore()) {
|
2012-05-02 21:55:32 +02:00
|
|
|
// Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)
|
|
|
|
ArmCallSEV ();
|
2011-11-16 13:53:25 +01:00
|
|
|
}
|
2011-11-02 00:41:52 +01:00
|
|
|
} else {
|
2012-05-02 21:55:32 +02:00
|
|
|
// Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)
|
|
|
|
ArmCallWFE ();
|
2011-11-02 00:41:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
// Write VBAR - The Vector table must be 32-byte aligned
|
2011-07-06 18:27:21 +02:00
|
|
|
ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);
|
|
|
|
ArmWriteVBar ((UINT32)PrePiVectorTable);
|
2011-07-01 13:09:00 +02:00
|
|
|
|
2011-07-06 18:27:21 +02:00
|
|
|
// If not primary Jump to Secondary Main
|
2011-09-23 01:01:13 +02:00
|
|
|
if (IS_PRIMARY_CORE(MpId)) {
|
2011-07-01 13:09:00 +02:00
|
|
|
// Goto primary Main.
|
2011-09-23 01:07:55 +02:00
|
|
|
PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);
|
2011-07-01 13:09:00 +02:00
|
|
|
} else {
|
2011-09-23 01:01:13 +02:00
|
|
|
SecondaryMain (MpId);
|
2011-07-01 13:09:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// DXE Core should always load and never return
|
|
|
|
ASSERT (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
PrePiCommonExceptionEntry (
|
|
|
|
IN UINT32 Entry,
|
|
|
|
IN UINT32 LR
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CHAR8 Buffer[100];
|
|
|
|
UINTN CharCount;
|
|
|
|
|
|
|
|
switch (Entry) {
|
|
|
|
case 0:
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SerialPortWrite ((UINT8 *) Buffer, CharCount);
|
|
|
|
while(1);
|
|
|
|
}
|