3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 // Hack to work in NT32
20 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
22 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
33 EFI_PEI_HOB_POINTERS Hob
;
35 Alloc
= AllocatePages (Pages
);
40 // find the HOB we just created, and change the type to EfiBootServicesCode
41 Hob
.Raw
= GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
);
42 while (Hob
.Raw
!= NULL
) {
43 if (Hob
.MemoryAllocation
->AllocDescriptor
.MemoryBaseAddress
== (UINTN
)Alloc
) {
44 Hob
.MemoryAllocation
->AllocDescriptor
.MemoryType
= EfiBootServicesCode
;
47 Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, GET_NEXT_HOB (Hob
));
52 FreePages (Alloc
, Pages
);
61 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
62 OUT UINT64
*ImageSize
,
63 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
67 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
70 ZeroMem (&ImageContext
, sizeof (ImageContext
));
72 ImageContext
.Handle
= PeCoffImage
;
73 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
75 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
76 ASSERT_EFI_ERROR (Status
);
80 // Allocate Memory for the image
82 Buffer
= AllocateCodePages (EFI_SIZE_TO_PAGES((UINT32
)ImageContext
.ImageSize
));
86 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)Buffer
;
89 // Load the image to our new buffer
91 Status
= PeCoffLoaderLoadImage (&ImageContext
);
92 ASSERT_EFI_ERROR (Status
);
95 // Relocate the image in our new buffer
97 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
98 ASSERT_EFI_ERROR (Status
);
101 *ImageAddress
= ImageContext
.ImageAddress
;
102 *ImageSize
= ImageContext
.ImageSize
;
103 *EntryPoint
= ImageContext
.EntryPoint
;
106 // Flush not needed for all architectures. We could have a processor specific
107 // function in this library that does the no-op if needed.
109 InvalidateInstructionCacheRange ((VOID
*)(UINTN
)*ImageAddress
, (UINTN
)*ImageSize
);
118 (EFIAPI
*DXE_CORE_ENTRY_POINT
) (
124 LoadDxeCoreFromFfsFile (
125 IN EFI_PEI_FILE_HANDLE FileHandle
,
131 EFI_PHYSICAL_ADDRESS ImageAddress
;
133 EFI_PHYSICAL_ADDRESS EntryPoint
;
137 EFI_FV_FILE_INFO FvFileInfo
;
139 Status
= FfsFindSectionData (EFI_SECTION_PE32
, FileHandle
, &PeCoffImage
);
140 if (EFI_ERROR (Status
)) {
145 Status
= LoadPeCoffImage (PeCoffImage
, &ImageAddress
, &ImageSize
, &EntryPoint
);
146 // For NT32 Debug Status = SecWinNtPeiLoadFile (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);
147 ASSERT_EFI_ERROR (Status
);
150 // Extract the DxeCore GUID file name.
152 Status
= FfsGetFileInfo (FileHandle
, &FvFileInfo
);
153 ASSERT_EFI_ERROR (Status
);
155 BuildModuleHob (&FvFileInfo
.FileName
, (EFI_PHYSICAL_ADDRESS
)(UINTN
)ImageAddress
, EFI_SIZE_TO_PAGES ((UINT32
) ImageSize
) * EFI_PAGE_SIZE
, EntryPoint
);
157 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "Loading DxeCore at 0x%10p EntryPoint=0x%10p\n", (VOID
*)(UINTN
)ImageAddress
, (VOID
*)(UINTN
)EntryPoint
));
160 if (StackSize
== 0) {
161 // User the current stack
163 ((DXE_CORE_ENTRY_POINT
)(UINTN
)EntryPoint
) (Hob
);
167 // Allocate 128KB for the Stack
169 BaseOfStack
= AllocatePages (EFI_SIZE_TO_PAGES (StackSize
));
170 ASSERT (BaseOfStack
!= NULL
);
173 // Compute the top of the stack we were allocated. Pre-allocate a UINTN
176 TopOfStack
= (VOID
*) ((UINTN
) BaseOfStack
+ EFI_SIZE_TO_PAGES (StackSize
) * EFI_PAGE_SIZE
- CPU_STACK_ALIGNMENT
);
177 TopOfStack
= ALIGN_POINTER (TopOfStack
, CPU_STACK_ALIGNMENT
);
180 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
182 UpdateStackHob ((EFI_PHYSICAL_ADDRESS
)(UINTN
) BaseOfStack
, StackSize
);
185 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)EntryPoint
,
193 // Should never get here as DXE Core does not return
194 DEBUG ((EFI_D_ERROR
, "DxeCore returned\n"));
197 return EFI_DEVICE_ERROR
;
205 IN UINTN
*FvInstance
, OPTIONAL
210 EFI_PEI_FV_HANDLE VolumeHandle
;
211 EFI_PEI_FILE_HANDLE FileHandle
= NULL
;
213 if (FvInstance
!= NULL
) {
215 // Caller passed in a specific FV to try, so only try that one
217 Status
= FfsFindNextVolume (*FvInstance
, &VolumeHandle
);
218 if (!EFI_ERROR (Status
)) {
219 Status
= FfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE
, VolumeHandle
, &FileHandle
);
222 Status
= FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_DXE_CORE
, &VolumeHandle
, &FileHandle
);
225 if (!EFI_ERROR (Status
)) {
226 return LoadDxeCoreFromFfsFile (FileHandle
, StackSize
);
240 EFI_PEI_FV_HANDLE VolumeHandle
;
241 EFI_PEI_FILE_HANDLE FileHandle
;
243 Status
= FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
, &VolumeHandle
, &FileHandle
);
244 if (!EFI_ERROR (Status
)) {
245 Status
= FfsProcessFvFile (FileHandle
);