]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/PrePi.c
2ca9c3b8fda6f5b6d5f3d99cec58357992f76da2
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
1 /** @file
2 *
3 * Copyright (c) 2011, ARM Limited. All rights reserved.
4 *
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
9 *
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.
12 *
13 **/
14
15 #include <PiPei.h>
16
17 #include <Library/DebugAgentLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/PrePiLib.h>
20 #include <Library/IoLib.h>
21 #include <Library/PrintLib.h>
22 #include <Library/PeCoffGetEntryPointLib.h>
23 #include <Library/PrePiHobListPointerLib.h>
24 #include <Library/TimerLib.h>
25 #include <Library/PerformanceLib.h>
26
27 #include <Ppi/GuidedSectionExtraction.h>
28 #include <Guid/LzmaDecompress.h>
29
30 #include "PrePi.h"
31 #include "LzmaDecompress.h"
32
33 VOID
34 PrePiCommonExceptionEntry (
35 IN UINT32 Entry,
36 IN UINT32 LR
37 );
38
39 EFI_STATUS
40 EFIAPI
41 ExtractGuidedSectionLibConstructor (
42 VOID
43 );
44
45 EFI_STATUS
46 EFIAPI
47 LzmaDecompressLibConstructor (
48 VOID
49 );
50
51 VOID
52 PrePiMain (
53 IN UINTN UefiMemoryBase,
54 IN UINTN StacksBase,
55 IN UINTN GlobalVariableBase,
56 IN UINT64 StartTimeStamp
57 )
58 {
59 EFI_HOB_HANDOFF_INFO_TABLE* HobList;
60 EFI_STATUS Status;
61 CHAR8 Buffer[100];
62 UINTN CharCount;
63 UINTN StacksSize;
64
65 // Enable program flow prediction, if supported.
66 ArmEnableBranchPrediction ();
67
68 if (FixedPcdGet32(PcdVFPEnabled)) {
69 ArmEnableVFP();
70 }
71
72 // Initialize the Serial Port
73 SerialPortInitialize ();
74 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware built at %a on %a\n\r",__TIME__, __DATE__);
75 SerialPortWrite ((UINT8 *) Buffer, CharCount);
76
77 // Initialize the Debug Agent for Source Level Debugging
78 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
79 SaveAndSetDebugTimerInterrupt (TRUE);
80
81 // Declare the PI/UEFI memory region
82 HobList = HobConstructor (
83 (VOID*)UefiMemoryBase,
84 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),
85 (VOID*)UefiMemoryBase,
86 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks
87 );
88 PrePeiSetHobList (HobList);
89
90 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
91 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
92 ASSERT_EFI_ERROR (Status);
93
94 // Create the Stacks HOB (reserve the memory for all stacks)
95 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));
96 BuildStackHob (StacksBase, StacksSize);
97
98 // Set the Boot Mode
99 SetBootMode (ArmPlatformGetBootMode ());
100
101 // Initialize Platform HOBs (CpuHob and FvHob)
102 Status = PlatformPeim ();
103 ASSERT_EFI_ERROR (Status);
104
105 BuildMemoryTypeInformationHob ();
106
107 // Now, the HOB List has been initialized, we can register performance information
108 PERF_START (NULL, "PEI", NULL, StartTimeStamp);
109
110 // SEC phase needs to run library constructors by hand.
111 ExtractGuidedSectionLibConstructor ();
112 LzmaDecompressLibConstructor ();
113
114 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
115 BuildPeCoffLoaderHob ();
116 BuildExtractSectionHob (
117 &gLzmaCustomDecompressGuid,
118 LzmaGuidedSectionGetInfo,
119 LzmaGuidedSectionExtraction
120 );
121
122 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
123 Status = DecompressFirstFv ();
124 ASSERT_EFI_ERROR (Status);
125
126 // Load the DXE Core and transfer control to it
127 Status = LoadDxeCoreFromFv (NULL, 0);
128 ASSERT_EFI_ERROR (Status);
129 }
130
131 VOID
132 CEntryPoint (
133 IN UINTN MpId,
134 IN UINTN UefiMemoryBase,
135 IN UINTN StacksBase,
136 IN UINTN GlobalVariableBase
137 )
138 {
139 UINT64 StartTimeStamp;
140
141 if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {
142 // Initialize the Timer Library to setup the Timer HW controller
143 TimerConstructor ();
144 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
145 StartTimeStamp = GetPerformanceCounter ();
146 } else {
147 StartTimeStamp = 0;
148 }
149
150 // Clean Data cache
151 ArmCleanInvalidateDataCache ();
152
153 // Invalidate instruction cache
154 ArmInvalidateInstructionCache ();
155
156 //TODO:Drain Write Buffer
157
158 // Enable Instruction & Data caches
159 ArmEnableDataCache ();
160 ArmEnableInstructionCache ();
161
162 // Write VBAR - The Vector table must be 32-byte aligned
163 ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);
164 ArmWriteVBar ((UINT32)PrePiVectorTable);
165
166 // If not primary Jump to Secondary Main
167 if (IS_PRIMARY_CORE(MpId)) {
168 // Goto primary Main.
169 PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);
170 } else {
171 SecondaryMain (MpId);
172 }
173
174 // DXE Core should always load and never return
175 ASSERT (FALSE);
176 }
177
178 VOID
179 PrePiCommonExceptionEntry (
180 IN UINT32 Entry,
181 IN UINT32 LR
182 )
183 {
184 CHAR8 Buffer[100];
185 UINTN CharCount;
186
187 switch (Entry) {
188 case 0:
189 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);
190 break;
191 case 1:
192 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);
193 break;
194 case 2:
195 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);
196 break;
197 case 3:
198 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);
199 break;
200 case 4:
201 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);
202 break;
203 case 5:
204 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);
205 break;
206 case 6:
207 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);
208 break;
209 case 7:
210 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);
211 break;
212 default:
213 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);
214 break;
215 }
216 SerialPortWrite ((UINT8 *) Buffer, CharCount);
217 while(1);
218 }