]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/PrePi/PrePi.c
ArmVirtPkg/PrePi: run all library constructors by hand
[mirror_edk2.git] / ArmVirtPkg / PrePi / PrePi.c
CommitLineData
f9a9d2dc
AB
1/** @file\r
2*\r
3* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include <PiPei.h>\r
16\r
17#include <Library/PrePiLib.h>\r
18#include <Library/PrintLib.h>\r
19#include <Library/PeCoffGetEntryPointLib.h>\r
20#include <Library/PrePiHobListPointerLib.h>\r
21#include <Library/TimerLib.h>\r
22#include <Library/PerformanceLib.h>\r
c9e5618f 23#include <Library/CacheMaintenanceLib.h>\r
f9a9d2dc
AB
24\r
25#include <Ppi/GuidedSectionExtraction.h>\r
26#include <Ppi/ArmMpCoreInfo.h>\r
27#include <Guid/LzmaDecompress.h>\r
f9a9d2dc
AB
28\r
29#include "PrePi.h"\r
30#include "LzmaDecompress.h"\r
31\r
af47c618 32VOID\r
f9a9d2dc 33EFIAPI\r
af47c618 34ProcessLibraryConstructorList (\r
f9a9d2dc
AB
35 VOID\r
36 );\r
37\r
f9a9d2dc
AB
38EFI_STATUS\r
39GetPlatformPpi (\r
40 IN EFI_GUID *PpiGuid,\r
41 OUT VOID **Ppi\r
42 )\r
43{\r
44 UINTN PpiListSize;\r
45 UINTN PpiListCount;\r
46 EFI_PEI_PPI_DESCRIPTOR *PpiList;\r
47 UINTN Index;\r
48\r
49 PpiListSize = 0;\r
50 ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);\r
51 PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);\r
52 for (Index = 0; Index < PpiListCount; Index++, PpiList++) {\r
53 if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {\r
54 *Ppi = PpiList->Ppi;\r
55 return EFI_SUCCESS;\r
56 }\r
57 }\r
58\r
59 return EFI_NOT_FOUND;\r
60}\r
61\r
62VOID\r
63PrePiMain (\r
64 IN UINTN UefiMemoryBase,\r
65 IN UINTN StacksBase,\r
f9a9d2dc
AB
66 IN UINT64 StartTimeStamp\r
67 )\r
68{\r
69 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
70 EFI_STATUS Status;\r
71 CHAR8 Buffer[100];\r
72 UINTN CharCount;\r
73 UINTN StacksSize;\r
74\r
75 // Initialize the architecture specific bits\r
76 ArchInitialize ();\r
77\r
f9a9d2dc
AB
78 // Declare the PI/UEFI memory region\r
79 HobList = HobConstructor (\r
80 (VOID*)UefiMemoryBase,\r
81 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
82 (VOID*)UefiMemoryBase,\r
83 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
84 );\r
85 PrePeiSetHobList (HobList);\r
86\r
c9e5618f
AB
87 //\r
88 // Ensure that the loaded image is invalidated in the caches, so that any\r
89 // modifications we made with the caches and MMU off (such as the applied\r
90 // relocations) don't become invisible once we turn them on.\r
91 //\r
92 InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r
93\r
f9a9d2dc
AB
94 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
95 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
96 ASSERT_EFI_ERROR (Status);\r
97\r
c9e5618f
AB
98 // Initialize the Serial Port\r
99 SerialPortInitialize ();\r
100 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
101 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
102 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
103\r
f9a9d2dc
AB
104 // Create the Stacks HOB (reserve the memory for all stacks)\r
105 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
106 BuildStackHob (StacksBase, StacksSize);\r
107\r
f9a9d2dc
AB
108 //TODO: Call CpuPei as a library\r
109 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
110\r
111 // Set the Boot Mode\r
112 SetBootMode (ArmPlatformGetBootMode ());\r
113\r
114 // Initialize Platform HOBs (CpuHob and FvHob)\r
115 Status = PlatformPeim ();\r
116 ASSERT_EFI_ERROR (Status);\r
117\r
118 // Now, the HOB List has been initialized, we can register performance information\r
119 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
120\r
121 // SEC phase needs to run library constructors by hand.\r
af47c618 122 ProcessLibraryConstructorList ();\r
f9a9d2dc
AB
123\r
124 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
125 BuildPeCoffLoaderHob ();\r
126 BuildExtractSectionHob (\r
127 &gLzmaCustomDecompressGuid,\r
128 LzmaGuidedSectionGetInfo,\r
129 LzmaGuidedSectionExtraction\r
130 );\r
131\r
132 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
133 Status = DecompressFirstFv ();\r
134 ASSERT_EFI_ERROR (Status);\r
135\r
136 // Load the DXE Core and transfer control to it\r
137 Status = LoadDxeCoreFromFv (NULL, 0);\r
138 ASSERT_EFI_ERROR (Status);\r
139}\r
140\r
141VOID\r
142CEntryPoint (\r
143 IN UINTN MpId,\r
144 IN UINTN UefiMemoryBase,\r
5eeba3b7 145 IN UINTN StacksBase\r
f9a9d2dc
AB
146 )\r
147{\r
148 UINT64 StartTimeStamp;\r
149\r
150 // Initialize the platform specific controllers\r
151 ArmPlatformInitialize (MpId);\r
152\r
153 if (PerformanceMeasurementEnabled ()) {\r
154 // Initialize the Timer Library to setup the Timer HW controller\r
155 TimerConstructor ();\r
156 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
157 StartTimeStamp = GetPerformanceCounter ();\r
158 } else {\r
159 StartTimeStamp = 0;\r
160 }\r
161\r
162 // Data Cache enabled on Primary core when MMU is enabled.\r
163 ArmDisableDataCache ();\r
f9a9d2dc
AB
164 // Invalidate instruction cache\r
165 ArmInvalidateInstructionCache ();\r
166 // Enable Instruction Caches on all cores.\r
167 ArmEnableInstructionCache ();\r
168\r
5eeba3b7 169 PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r
f9a9d2dc
AB
170\r
171 // DXE Core should always load and never return\r
172 ASSERT (FALSE);\r
173}\r