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