3 Copyright (c) 2008 - 2009, Apple Inc. 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
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.
18 // Hack to work in NT32
26 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
28 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
36 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
37 OUT UINT64
*ImageSize
,
38 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
42 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
45 ZeroMem (&ImageContext
, sizeof (ImageContext
));
47 ImageContext
.Handle
= PeCoffImage
;
48 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
50 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
51 ASSERT_EFI_ERROR (Status
);
55 // Allocate Memory for the image
57 Buffer
= AllocatePages (EFI_SIZE_TO_PAGES((UINT32
)ImageContext
.ImageSize
));
61 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)Buffer
;
64 // Load the image to our new buffer
66 Status
= PeCoffLoaderLoadImage (&ImageContext
);
67 ASSERT_EFI_ERROR (Status
);
70 // Relocate the image in our new buffer
72 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
73 ASSERT_EFI_ERROR (Status
);
76 *ImageAddress
= ImageContext
.ImageAddress
;
77 *ImageSize
= ImageContext
.ImageSize
;
78 *EntryPoint
= ImageContext
.EntryPoint
;
81 // Flush not needed for all architectures. We could have a processor specific
82 // function in this library that does the no-op if needed.
84 InvalidateInstructionCacheRange ((VOID
*)(UINTN
)*ImageAddress
, (UINTN
)*ImageSize
);
93 (EFIAPI
*DXE_CORE_ENTRY_POINT
) (
99 LoadDxeCoreFromFfsFile (
100 IN EFI_PEI_FILE_HANDLE FileHandle
,
106 EFI_PHYSICAL_ADDRESS ImageAddress
;
108 EFI_PHYSICAL_ADDRESS EntryPoint
;
112 EFI_FV_FILE_INFO FvFileInfo
;
114 Status
= FfsFindSectionData (EFI_SECTION_PE32
, FileHandle
, &PeCoffImage
);
115 if (EFI_ERROR (Status
)) {
120 Status
= LoadPeCoffImage (PeCoffImage
, &ImageAddress
, &ImageSize
, &EntryPoint
);
121 // For NT32 Debug Status = SecWinNtPeiLoadFile (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);
122 ASSERT_EFI_ERROR (Status
);
125 // Extract the DxeCore GUID file name.
127 Status
= FfsGetFileInfo (FileHandle
, &FvFileInfo
);
128 ASSERT_EFI_ERROR (Status
);
130 BuildModuleHob (&FvFileInfo
.FileName
, (EFI_PHYSICAL_ADDRESS
)(UINTN
)ImageAddress
, EFI_SIZE_TO_PAGES ((UINT32
) ImageSize
) * EFI_PAGE_SIZE
, EntryPoint
);
132 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "Loading DxeCore at 0x%10p EntryPoint=0x%10p\n", (VOID
*)(UINTN
)ImageAddress
, (VOID
*)(UINTN
)EntryPoint
));
135 if (StackSize
== 0) {
136 // User the current stack
138 ((DXE_CORE_ENTRY_POINT
)(UINTN
)EntryPoint
) (Hob
);
142 // Allocate 128KB for the Stack
144 BaseOfStack
= AllocatePages (EFI_SIZE_TO_PAGES (StackSize
));
145 ASSERT (BaseOfStack
!= NULL
);
148 // Compute the top of the stack we were allocated. Pre-allocate a UINTN
151 TopOfStack
= (VOID
*) ((UINTN
) BaseOfStack
+ EFI_SIZE_TO_PAGES (StackSize
) * EFI_PAGE_SIZE
- CPU_STACK_ALIGNMENT
);
152 TopOfStack
= ALIGN_POINTER (TopOfStack
, CPU_STACK_ALIGNMENT
);
155 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
157 UpdateStackHob ((EFI_PHYSICAL_ADDRESS
)(UINTN
) BaseOfStack
, StackSize
);
160 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)EntryPoint
,
168 // Should never get here as DXE Core does not return
169 DEBUG ((EFI_D_ERROR
, "DxeCore returned\n"));
172 return EFI_DEVICE_ERROR
;
180 IN UINTN
*FvInstance
, OPTIONAL
185 EFI_PEI_FV_HANDLE VolumeHandle
;
186 EFI_PEI_FILE_HANDLE FileHandle
= NULL
;
188 if (FvInstance
!= NULL
) {
190 // Caller passed in a specific FV to try, so only try that one
192 Status
= FfsFindNextVolume (*FvInstance
, &VolumeHandle
);
193 if (!EFI_ERROR (Status
)) {
194 Status
= FfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE
, VolumeHandle
, &FileHandle
);
197 Status
= FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_DXE_CORE
, &VolumeHandle
, &FileHandle
);
200 if (!EFI_ERROR (Status
)) {
201 return LoadDxeCoreFromFfsFile (FileHandle
, StackSize
);
215 EFI_PEI_FV_HANDLE VolumeHandle
;
216 EFI_PEI_FILE_HANDLE FileHandle
;
218 Status
= FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
, &VolumeHandle
, &FileHandle
);
219 if (!EFI_ERROR (Status
)) {
220 Status
= FfsProcessFvFile (FileHandle
);