]>
Commit | Line | Data |
---|---|---|
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 | |
0ae69a2e | 16 | #include <Pi/PiBootMode.h>\r |
f9a9d2dc AB |
17 | \r |
18 | #include <Library/PrePiLib.h>\r | |
19 | #include <Library/PrintLib.h>\r | |
20 | #include <Library/PeCoffGetEntryPointLib.h>\r | |
21 | #include <Library/PrePiHobListPointerLib.h>\r | |
22 | #include <Library/TimerLib.h>\r | |
23 | #include <Library/PerformanceLib.h>\r | |
c9e5618f | 24 | #include <Library/CacheMaintenanceLib.h>\r |
f9a9d2dc AB |
25 | \r |
26 | #include <Ppi/GuidedSectionExtraction.h>\r | |
27 | #include <Ppi/ArmMpCoreInfo.h>\r | |
28 | #include <Guid/LzmaDecompress.h>\r | |
f9a9d2dc AB |
29 | \r |
30 | #include "PrePi.h"\r | |
31 | #include "LzmaDecompress.h"\r | |
32 | \r | |
af47c618 | 33 | VOID\r |
f9a9d2dc | 34 | EFIAPI\r |
af47c618 | 35 | ProcessLibraryConstructorList (\r |
f9a9d2dc AB |
36 | VOID\r |
37 | );\r | |
38 | \r | |
f9a9d2dc AB |
39 | VOID\r |
40 | PrePiMain (\r | |
41 | IN UINTN UefiMemoryBase,\r | |
42 | IN UINTN StacksBase,\r | |
f9a9d2dc AB |
43 | IN UINT64 StartTimeStamp\r |
44 | )\r | |
45 | {\r | |
46 | EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r | |
47 | EFI_STATUS Status;\r | |
48 | CHAR8 Buffer[100];\r | |
49 | UINTN CharCount;\r | |
50 | UINTN StacksSize;\r | |
51 | \r | |
52 | // Initialize the architecture specific bits\r | |
53 | ArchInitialize ();\r | |
54 | \r | |
f9a9d2dc AB |
55 | // Declare the PI/UEFI memory region\r |
56 | HobList = HobConstructor (\r | |
57 | (VOID*)UefiMemoryBase,\r | |
58 | FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r | |
59 | (VOID*)UefiMemoryBase,\r | |
60 | (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r | |
61 | );\r | |
62 | PrePeiSetHobList (HobList);\r | |
63 | \r | |
c9e5618f AB |
64 | //\r |
65 | // Ensure that the loaded image is invalidated in the caches, so that any\r | |
66 | // modifications we made with the caches and MMU off (such as the applied\r | |
67 | // relocations) don't become invisible once we turn them on.\r | |
68 | //\r | |
69 | InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r | |
70 | \r | |
f9a9d2dc AB |
71 | // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r |
72 | Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r | |
73 | ASSERT_EFI_ERROR (Status);\r | |
74 | \r | |
c9e5618f AB |
75 | // Initialize the Serial Port\r |
76 | SerialPortInitialize ();\r | |
77 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r | |
78 | (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r | |
79 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r | |
80 | \r | |
f9a9d2dc AB |
81 | // Create the Stacks HOB (reserve the memory for all stacks)\r |
82 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r | |
83 | BuildStackHob (StacksBase, StacksSize);\r | |
84 | \r | |
f9a9d2dc AB |
85 | //TODO: Call CpuPei as a library\r |
86 | BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r | |
87 | \r | |
88 | // Set the Boot Mode\r | |
0ae69a2e | 89 | SetBootMode (BOOT_WITH_FULL_CONFIGURATION);\r |
f9a9d2dc AB |
90 | \r |
91 | // Initialize Platform HOBs (CpuHob and FvHob)\r | |
92 | Status = PlatformPeim ();\r | |
93 | ASSERT_EFI_ERROR (Status);\r | |
94 | \r | |
95 | // Now, the HOB List has been initialized, we can register performance information\r | |
96 | PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r | |
97 | \r | |
98 | // SEC phase needs to run library constructors by hand.\r | |
af47c618 | 99 | ProcessLibraryConstructorList ();\r |
f9a9d2dc AB |
100 | \r |
101 | // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r | |
102 | BuildPeCoffLoaderHob ();\r | |
103 | BuildExtractSectionHob (\r | |
104 | &gLzmaCustomDecompressGuid,\r | |
105 | LzmaGuidedSectionGetInfo,\r | |
106 | LzmaGuidedSectionExtraction\r | |
107 | );\r | |
108 | \r | |
109 | // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r | |
110 | Status = DecompressFirstFv ();\r | |
111 | ASSERT_EFI_ERROR (Status);\r | |
112 | \r | |
113 | // Load the DXE Core and transfer control to it\r | |
114 | Status = LoadDxeCoreFromFv (NULL, 0);\r | |
115 | ASSERT_EFI_ERROR (Status);\r | |
116 | }\r | |
117 | \r | |
118 | VOID\r | |
119 | CEntryPoint (\r | |
120 | IN UINTN MpId,\r | |
121 | IN UINTN UefiMemoryBase,\r | |
5eeba3b7 | 122 | IN UINTN StacksBase\r |
f9a9d2dc AB |
123 | )\r |
124 | {\r | |
125 | UINT64 StartTimeStamp;\r | |
126 | \r | |
f9a9d2dc AB |
127 | if (PerformanceMeasurementEnabled ()) {\r |
128 | // Initialize the Timer Library to setup the Timer HW controller\r | |
129 | TimerConstructor ();\r | |
130 | // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r | |
131 | StartTimeStamp = GetPerformanceCounter ();\r | |
132 | } else {\r | |
133 | StartTimeStamp = 0;\r | |
134 | }\r | |
135 | \r | |
136 | // Data Cache enabled on Primary core when MMU is enabled.\r | |
137 | ArmDisableDataCache ();\r | |
f9a9d2dc AB |
138 | // Invalidate instruction cache\r |
139 | ArmInvalidateInstructionCache ();\r | |
140 | // Enable Instruction Caches on all cores.\r | |
141 | ArmEnableInstructionCache ();\r | |
142 | \r | |
5eeba3b7 | 143 | PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r |
f9a9d2dc AB |
144 | \r |
145 | // DXE Core should always load and never return\r | |
146 | ASSERT (FALSE);\r | |
147 | }\r |