]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/PrePi/PrePi.c
BaseTools/tools_def AARCH64 ARM: suppres PIE sections via linker script
[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
f9a9d2dc
AB
32EFI_STATUS\r
33EFIAPI\r
34ExtractGuidedSectionLibConstructor (\r
35 VOID\r
36 );\r
37\r
38EFI_STATUS\r
39EFIAPI\r
40LzmaDecompressLibConstructor (\r
41 VOID\r
42 );\r
43\r
f9a9d2dc
AB
44EFI_STATUS\r
45GetPlatformPpi (\r
46 IN EFI_GUID *PpiGuid,\r
47 OUT VOID **Ppi\r
48 )\r
49{\r
50 UINTN PpiListSize;\r
51 UINTN PpiListCount;\r
52 EFI_PEI_PPI_DESCRIPTOR *PpiList;\r
53 UINTN Index;\r
54\r
55 PpiListSize = 0;\r
56 ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);\r
57 PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);\r
58 for (Index = 0; Index < PpiListCount; Index++, PpiList++) {\r
59 if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {\r
60 *Ppi = PpiList->Ppi;\r
61 return EFI_SUCCESS;\r
62 }\r
63 }\r
64\r
65 return EFI_NOT_FOUND;\r
66}\r
67\r
68VOID\r
69PrePiMain (\r
70 IN UINTN UefiMemoryBase,\r
71 IN UINTN StacksBase,\r
f9a9d2dc
AB
72 IN UINT64 StartTimeStamp\r
73 )\r
74{\r
75 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
76 EFI_STATUS Status;\r
77 CHAR8 Buffer[100];\r
78 UINTN CharCount;\r
79 UINTN StacksSize;\r
80\r
81 // Initialize the architecture specific bits\r
82 ArchInitialize ();\r
83\r
f9a9d2dc
AB
84 // Declare the PI/UEFI memory region\r
85 HobList = HobConstructor (\r
86 (VOID*)UefiMemoryBase,\r
87 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
88 (VOID*)UefiMemoryBase,\r
89 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
90 );\r
91 PrePeiSetHobList (HobList);\r
92\r
c9e5618f
AB
93 //\r
94 // Ensure that the loaded image is invalidated in the caches, so that any\r
95 // modifications we made with the caches and MMU off (such as the applied\r
96 // relocations) don't become invisible once we turn them on.\r
97 //\r
98 InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r
99\r
f9a9d2dc
AB
100 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
101 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
102 ASSERT_EFI_ERROR (Status);\r
103\r
c9e5618f
AB
104 // Initialize the Serial Port\r
105 SerialPortInitialize ();\r
106 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
107 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
108 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
109\r
f9a9d2dc
AB
110 // Create the Stacks HOB (reserve the memory for all stacks)\r
111 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
112 BuildStackHob (StacksBase, StacksSize);\r
113\r
f9a9d2dc
AB
114 //TODO: Call CpuPei as a library\r
115 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
116\r
117 // Set the Boot Mode\r
118 SetBootMode (ArmPlatformGetBootMode ());\r
119\r
120 // Initialize Platform HOBs (CpuHob and FvHob)\r
121 Status = PlatformPeim ();\r
122 ASSERT_EFI_ERROR (Status);\r
123\r
124 // Now, the HOB List has been initialized, we can register performance information\r
125 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
126\r
127 // SEC phase needs to run library constructors by hand.\r
128 ExtractGuidedSectionLibConstructor ();\r
129 LzmaDecompressLibConstructor ();\r
130\r
131 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
132 BuildPeCoffLoaderHob ();\r
133 BuildExtractSectionHob (\r
134 &gLzmaCustomDecompressGuid,\r
135 LzmaGuidedSectionGetInfo,\r
136 LzmaGuidedSectionExtraction\r
137 );\r
138\r
139 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
140 Status = DecompressFirstFv ();\r
141 ASSERT_EFI_ERROR (Status);\r
142\r
143 // Load the DXE Core and transfer control to it\r
144 Status = LoadDxeCoreFromFv (NULL, 0);\r
145 ASSERT_EFI_ERROR (Status);\r
146}\r
147\r
148VOID\r
149CEntryPoint (\r
150 IN UINTN MpId,\r
151 IN UINTN UefiMemoryBase,\r
5eeba3b7 152 IN UINTN StacksBase\r
f9a9d2dc
AB
153 )\r
154{\r
155 UINT64 StartTimeStamp;\r
156\r
157 // Initialize the platform specific controllers\r
158 ArmPlatformInitialize (MpId);\r
159\r
160 if (PerformanceMeasurementEnabled ()) {\r
161 // Initialize the Timer Library to setup the Timer HW controller\r
162 TimerConstructor ();\r
163 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
164 StartTimeStamp = GetPerformanceCounter ();\r
165 } else {\r
166 StartTimeStamp = 0;\r
167 }\r
168\r
169 // Data Cache enabled on Primary core when MMU is enabled.\r
170 ArmDisableDataCache ();\r
f9a9d2dc
AB
171 // Invalidate instruction cache\r
172 ArmInvalidateInstructionCache ();\r
173 // Enable Instruction Caches on all cores.\r
174 ArmEnableInstructionCache ();\r
175\r
5eeba3b7 176 PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r
f9a9d2dc
AB
177\r
178 // DXE Core should always load and never return\r
179 ASSERT (FALSE);\r
180}\r