3 * Copyright (c) 2011, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DebugAgentLib.h>
18 #include <Library/PrePiLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/PrintLib.h>
21 #include <Library/PeCoffGetEntryPointLib.h>
22 #include <Library/PrePiHobListPointerLib.h>
23 #include <Library/TimerLib.h>
24 #include <Library/PerformanceLib.h>
26 #include <Ppi/GuidedSectionExtraction.h>
27 #include <Guid/LzmaDecompress.h>
30 #include "LzmaDecompress.h"
33 PrePiCommonExceptionEntry (
40 ExtractGuidedSectionLibConstructor (
46 LzmaDecompressLibConstructor (
52 IN UINTN UefiMemoryBase
,
53 IN UINT64 StartTimeStamp
56 EFI_HOB_HANDOFF_INFO_TABLE
* HobList
;
64 // Enable program flow prediction, if supported.
65 ArmEnableBranchPrediction ();
67 if (FixedPcdGet32(PcdVFPEnabled
)) {
71 // Initialize the Serial Port
72 SerialPortInitialize ();
73 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"UEFI firmware built at %a on %a\n\r",__TIME__
, __DATE__
);
74 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);
76 // Initialize the Debug Agent for Source Level Debugging
77 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
78 SaveAndSetDebugTimerInterrupt (TRUE
);
80 UefiMemoryTop
= UefiMemoryBase
+ FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
);
81 StacksSize
= PcdGet32 (PcdCPUCoresNonSecStackSize
) * PcdGet32 (PcdMPCoreMaxCores
);
82 StacksBase
= UefiMemoryTop
- StacksSize
;
84 // Check the PcdCPUCoresNonSecStackBase match with the calculated StackBase
85 ASSERT (StacksBase
== PcdGet32 (PcdCPUCoresNonSecStackBase
));
87 // Declare the PI/UEFI memory region
88 HobList
= HobConstructor (
89 (VOID
*)UefiMemoryBase
,
90 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
),
91 (VOID
*)UefiMemoryBase
,
92 (VOID
*)StacksBase
// The top of the UEFI Memory is reserved for the stacks
94 PrePeiSetHobList (HobList
);
96 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
97 Status
= MemoryPeim (UefiMemoryBase
, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
));
98 ASSERT_EFI_ERROR (Status
);
100 // Create the Stacks HOB (reserve the memory for all stacks)
101 BuildStackHob (StacksBase
, StacksSize
);
104 SetBootMode (ArmPlatformGetBootMode ());
106 // Initialize Platform HOBs (CpuHob and FvHob)
107 Status
= PlatformPeim ();
108 ASSERT_EFI_ERROR (Status
);
110 BuildMemoryTypeInformationHob ();
112 // Now, the HOB List has been initialized, we can register performance information
113 PERF_START (NULL
, "PEI", NULL
, StartTimeStamp
);
115 // SEC phase needs to run library constructors by hand.
116 ExtractGuidedSectionLibConstructor ();
117 LzmaDecompressLibConstructor ();
119 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
120 BuildPeCoffLoaderHob ();
121 BuildExtractSectionHob (
122 &gLzmaCustomDecompressGuid
,
123 LzmaGuidedSectionGetInfo
,
124 LzmaGuidedSectionExtraction
127 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
128 Status
= DecompressFirstFv ();
129 ASSERT_EFI_ERROR (Status
);
131 // Load the DXE Core and transfer control to it
132 Status
= LoadDxeCoreFromFv (NULL
, 0);
133 ASSERT_EFI_ERROR (Status
);
139 IN UINTN UefiMemoryBase
142 UINT64 StartTimeStamp
;
144 if ((CoreId
== ARM_PRIMARY_CORE
) && PerformanceMeasurementEnabled ()) {
145 // Initialize the Timer Library to setup the Timer HW controller
147 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
148 StartTimeStamp
= GetPerformanceCounter ();
154 ArmCleanInvalidateDataCache ();
156 // Invalidate instruction cache
157 ArmInvalidateInstructionCache ();
159 //TODO:Drain Write Buffer
161 // Enable Instruction & Data caches
162 ArmEnableDataCache ();
163 ArmEnableInstructionCache ();
165 // Write VBAR - The Vector table must be 32-byte aligned
166 ASSERT (((UINT32
)PrePiVectorTable
& ((1 << 5)-1)) == 0);
167 ArmWriteVBar ((UINT32
)PrePiVectorTable
);
169 // If not primary Jump to Secondary Main
170 if (CoreId
== ARM_PRIMARY_CORE
) {
171 // Goto primary Main.
172 PrimaryMain (UefiMemoryBase
, StartTimeStamp
);
174 SecondaryMain (CoreId
);
177 // DXE Core should always load and never return
182 PrePiCommonExceptionEntry (
192 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"Reset Exception at 0x%X\n\r",LR
);
195 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"Undefined Exception at 0x%X\n\r",LR
);
198 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"SWI Exception at 0x%X\n\r",LR
);
201 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"PrefetchAbort Exception at 0x%X\n\r",LR
);
204 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"DataAbort Exception at 0x%X\n\r",LR
);
207 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"Reserved Exception at 0x%X\n\r",LR
);
210 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"IRQ Exception at 0x%X\n\r",LR
);
213 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"FIQ Exception at 0x%X\n\r",LR
);
216 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"Unknown Exception at 0x%X\n\r",LR
);
219 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);