]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/SecCore/FindPeiCore.c
UefiCpuPkg: Remove redundant library classes, Ppis and GUIDs
[mirror_edk2.git] / UefiCpuPkg / SecCore / FindPeiCore.c
1 /** @file
2 Locate the entry point for the PEI Core
3
4 Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
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 "SecMain.h"
18
19 /**
20 Find core image base.
21
22 @param BootFirmwareVolumePtr Point to the boot firmware volume.
23 @param SecCoreImageBase The base address of the SEC core image.
24 @param PeiCoreImageBase The base address of the PEI core image.
25
26 **/
27 EFI_STATUS
28 EFIAPI
29 FindImageBase (
30 IN EFI_FIRMWARE_VOLUME_HEADER *BootFirmwareVolumePtr,
31 OUT EFI_PHYSICAL_ADDRESS *SecCoreImageBase,
32 OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase
33 )
34 {
35 EFI_PHYSICAL_ADDRESS CurrentAddress;
36 EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume;
37 EFI_FFS_FILE_HEADER *File;
38 UINT32 Size;
39 EFI_PHYSICAL_ADDRESS EndOfFile;
40 EFI_COMMON_SECTION_HEADER *Section;
41 EFI_PHYSICAL_ADDRESS EndOfSection;
42
43 *SecCoreImageBase = 0;
44 *PeiCoreImageBase = 0;
45
46 CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) BootFirmwareVolumePtr;
47 EndOfFirmwareVolume = CurrentAddress + BootFirmwareVolumePtr->FvLength;
48
49 //
50 // Loop through the FFS files in the Boot Firmware Volume
51 //
52 for (EndOfFile = CurrentAddress + BootFirmwareVolumePtr->HeaderLength; ; ) {
53
54 CurrentAddress = (EndOfFile + 7) & 0xfffffffffffffff8ULL;
55 if (CurrentAddress > EndOfFirmwareVolume) {
56 return EFI_NOT_FOUND;
57 }
58
59 File = (EFI_FFS_FILE_HEADER*)(UINTN) CurrentAddress;
60 if (IS_FFS_FILE2 (File)) {
61 Size = FFS_FILE2_SIZE (File);
62 if (Size <= 0x00FFFFFF) {
63 return EFI_NOT_FOUND;
64 }
65 } else {
66 Size = FFS_FILE_SIZE (File);
67 if (Size < sizeof (EFI_FFS_FILE_HEADER)) {
68 return EFI_NOT_FOUND;
69 }
70 }
71
72 EndOfFile = CurrentAddress + Size;
73 if (EndOfFile > EndOfFirmwareVolume) {
74 return EFI_NOT_FOUND;
75 }
76
77 //
78 // Look for SEC Core / PEI Core files
79 //
80 if (File->Type != EFI_FV_FILETYPE_SECURITY_CORE &&
81 File->Type != EFI_FV_FILETYPE_PEI_CORE) {
82 continue;
83 }
84
85 //
86 // Loop through the FFS file sections within the FFS file
87 //
88 if (IS_FFS_FILE2 (File)) {
89 EndOfSection = (EFI_PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) File + sizeof (EFI_FFS_FILE_HEADER2));
90 } else {
91 EndOfSection = (EFI_PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) File + sizeof (EFI_FFS_FILE_HEADER));
92 }
93 for (;;) {
94 CurrentAddress = (EndOfSection + 3) & 0xfffffffffffffffcULL;
95 Section = (EFI_COMMON_SECTION_HEADER*)(UINTN) CurrentAddress;
96
97 if (IS_SECTION2 (Section)) {
98 Size = SECTION2_SIZE (Section);
99 if (Size <= 0x00FFFFFF) {
100 return EFI_NOT_FOUND;
101 }
102 } else {
103 Size = SECTION_SIZE (Section);
104 if (Size < sizeof (EFI_COMMON_SECTION_HEADER)) {
105 return EFI_NOT_FOUND;
106 }
107 }
108
109 EndOfSection = CurrentAddress + Size;
110 if (EndOfSection > EndOfFile) {
111 return EFI_NOT_FOUND;
112 }
113
114 //
115 // Look for executable sections
116 //
117 if (Section->Type == EFI_SECTION_PE32 || Section->Type == EFI_SECTION_TE) {
118 if (File->Type == EFI_FV_FILETYPE_SECURITY_CORE) {
119 if (IS_SECTION2 (Section)) {
120 *SecCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));
121 } else {
122 *SecCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));
123 }
124 } else {
125 if (IS_SECTION2 (Section)) {
126 *PeiCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));
127 } else {
128 *PeiCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));
129 }
130 }
131 break;
132 }
133 }
134
135 //
136 // Both SEC Core and PEI Core images found
137 //
138 if (*SecCoreImageBase != 0 && *PeiCoreImageBase != 0) {
139 return EFI_SUCCESS;
140 }
141 }
142 }
143
144 /**
145 Find and return Pei Core entry point.
146
147 It also find SEC and PEI Core file debug information. It will report them if
148 remote debug is enabled.
149
150 @param BootFirmwareVolumePtr Point to the boot firmware volume.
151 @param PeiCoreEntryPoint The entry point of the PEI core.
152
153 **/
154 VOID
155 EFIAPI
156 FindAndReportEntryPoints (
157 IN EFI_FIRMWARE_VOLUME_HEADER *BootFirmwareVolumePtr,
158 OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint
159 )
160 {
161 EFI_STATUS Status;
162 EFI_PHYSICAL_ADDRESS SecCoreImageBase;
163 EFI_PHYSICAL_ADDRESS PeiCoreImageBase;
164 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
165
166 //
167 // Find SEC Core and PEI Core image base
168 //
169 Status = FindImageBase (BootFirmwareVolumePtr, &SecCoreImageBase, &PeiCoreImageBase);
170 ASSERT_EFI_ERROR (Status);
171
172 ZeroMem ((VOID *) &ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT));
173 //
174 // Report SEC Core debug information when remote debug is enabled
175 //
176 ImageContext.ImageAddress = SecCoreImageBase;
177 ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);
178 PeCoffLoaderRelocateImageExtraAction (&ImageContext);
179
180 //
181 // Report PEI Core debug information when remote debug is enabled
182 //
183 ImageContext.ImageAddress = PeiCoreImageBase;
184 ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);
185 PeCoffLoaderRelocateImageExtraAction (&ImageContext);
186
187 //
188 // Find PEI Core entry point
189 //
190 Status = PeCoffLoaderGetEntryPoint ((VOID *) (UINTN) PeiCoreImageBase, (VOID**) PeiCoreEntryPoint);
191 if (EFI_ERROR (Status)) {
192 *PeiCoreEntryPoint = 0;
193 }
194
195 return;
196 }