]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmVirtPkg/PrePi/PrePi.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmVirtPkg / PrePi / PrePi.c
... / ...
CommitLineData
1/** @file\r
2*\r
3* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
4*\r
5* SPDX-License-Identifier: BSD-2-Clause-Patent\r
6*\r
7**/\r
8\r
9#include <PiPei.h>\r
10#include <Pi/PiBootMode.h>\r
11\r
12#include <Library/PeCoffLib.h>\r
13#include <Library/PrePiLib.h>\r
14#include <Library/PrintLib.h>\r
15#include <Library/PrePiHobListPointerLib.h>\r
16#include <Library/TimerLib.h>\r
17#include <Library/PerformanceLib.h>\r
18#include <Library/CacheMaintenanceLib.h>\r
19\r
20#include <Ppi/GuidedSectionExtraction.h>\r
21#include <Ppi/ArmMpCoreInfo.h>\r
22\r
23#include "PrePi.h"\r
24\r
25VOID\r
26EFIAPI\r
27ProcessLibraryConstructorList (\r
28 VOID\r
29 );\r
30\r
31VOID\r
32PrePiMain (\r
33 IN UINTN UefiMemoryBase,\r
34 IN UINTN StacksBase,\r
35 IN UINT64 StartTimeStamp\r
36 )\r
37{\r
38 EFI_HOB_HANDOFF_INFO_TABLE *HobList;\r
39 EFI_STATUS Status;\r
40 CHAR8 Buffer[100];\r
41 UINTN CharCount;\r
42 UINTN StacksSize;\r
43\r
44 // Initialize the architecture specific bits\r
45 ArchInitialize ();\r
46\r
47 // Declare the PI/UEFI memory region\r
48 HobList = HobConstructor (\r
49 (VOID *)UefiMemoryBase,\r
50 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
51 (VOID *)UefiMemoryBase,\r
52 (VOID *)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
53 );\r
54 PrePeiSetHobList (HobList);\r
55\r
56 //\r
57 // Ensure that the loaded image is invalidated in the caches, so that any\r
58 // modifications we made with the caches and MMU off (such as the applied\r
59 // relocations) don't become invisible once we turn them on.\r
60 //\r
61 InvalidateDataCacheRange ((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r
62\r
63 // SEC phase needs to run library constructors by hand.\r
64 ProcessLibraryConstructorList ();\r
65\r
66 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
67 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
68 ASSERT_EFI_ERROR (Status);\r
69\r
70 // Initialize the Serial Port\r
71 SerialPortInitialize ();\r
72 CharCount = AsciiSPrint (\r
73 Buffer,\r
74 sizeof (Buffer),\r
75 "UEFI firmware (version %s built at %a on %a)\n\r",\r
76 (CHAR16 *)PcdGetPtr (PcdFirmwareVersionString),\r
77 __TIME__,\r
78 __DATE__\r
79 );\r
80 SerialPortWrite ((UINT8 *)Buffer, CharCount);\r
81\r
82 // Create the Stacks HOB (reserve the memory for all stacks)\r
83 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
84 BuildStackHob (StacksBase, StacksSize);\r
85\r
86 // TODO: Call CpuPei as a library\r
87 BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));\r
88\r
89 // Set the Boot Mode\r
90 SetBootMode (BOOT_WITH_FULL_CONFIGURATION);\r
91\r
92 // Initialize Platform HOBs (CpuHob and FvHob)\r
93 Status = PlatformPeim ();\r
94 ASSERT_EFI_ERROR (Status);\r
95\r
96 // Now, the HOB List has been initialized, we can register performance information\r
97 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
98\r
99 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
100 Status = DecompressFirstFv ();\r
101 ASSERT_EFI_ERROR (Status);\r
102\r
103 // Load the DXE Core and transfer control to it\r
104 Status = LoadDxeCoreFromFv (NULL, 0);\r
105 ASSERT_EFI_ERROR (Status);\r
106}\r
107\r
108VOID\r
109CEntryPoint (\r
110 IN UINTN MpId,\r
111 IN UINTN UefiMemoryBase,\r
112 IN UINTN StacksBase\r
113 )\r
114{\r
115 UINT64 StartTimeStamp;\r
116\r
117 if (PerformanceMeasurementEnabled ()) {\r
118 // Initialize the Timer Library to setup the Timer HW controller\r
119 TimerConstructor ();\r
120 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
121 StartTimeStamp = GetPerformanceCounter ();\r
122 } else {\r
123 StartTimeStamp = 0;\r
124 }\r
125\r
126 // Data Cache enabled on Primary core when MMU is enabled.\r
127 ArmDisableDataCache ();\r
128 // Invalidate instruction cache\r
129 ArmInvalidateInstructionCache ();\r
130 // Enable Instruction Caches on all cores.\r
131 ArmEnableInstructionCache ();\r
132\r
133 PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r
134\r
135 // DXE Core should always load and never return\r
136 ASSERT (FALSE);\r
137}\r
138\r
139VOID\r
140RelocatePeCoffImage (\r
141 IN EFI_PEI_FV_HANDLE FwVolHeader,\r
142 IN PE_COFF_LOADER_READ_FILE ImageRead\r
143 )\r
144{\r
145 EFI_PEI_FILE_HANDLE FileHandle;\r
146 VOID *SectionData;\r
147 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r
148 EFI_STATUS Status;\r
149\r
150 FileHandle = NULL;\r
151 Status = FfsFindNextFile (\r
152 EFI_FV_FILETYPE_SECURITY_CORE,\r
153 FwVolHeader,\r
154 &FileHandle\r
155 );\r
156 ASSERT_EFI_ERROR (Status);\r
157\r
158 Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SectionData);\r
159 if (EFI_ERROR (Status)) {\r
160 Status = FfsFindSectionData (EFI_SECTION_TE, FileHandle, &SectionData);\r
161 }\r
162\r
163 ASSERT_EFI_ERROR (Status);\r
164\r
165 ZeroMem (&ImageContext, sizeof ImageContext);\r
166\r
167 ImageContext.Handle = (EFI_HANDLE)SectionData;\r
168 ImageContext.ImageRead = ImageRead;\r
169 PeCoffLoaderGetImageInfo (&ImageContext);\r
170\r
171 if (ImageContext.ImageAddress != (UINTN)SectionData) {\r
172 ImageContext.ImageAddress = (UINTN)SectionData;\r
173 PeCoffLoaderRelocateImage (&ImageContext);\r
174 }\r
175}\r