]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/DxeIplPeim/DxeLoad.c
Roll back changes to apply GetBestLanguage() in HiiDataBase. Exact language match...
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / DxeLoad.c
1 /** @file
2 Last PEIM.
3 Responsibility of this module is to load the DXE Core from a Firmware Volume.
4
5 Copyright (c) 2006 - 2009, Intel Corporation. <BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "DxeIpl.h"
17
18
19 //
20 // Module Globals used in the DXE to PEI hand off
21 // These must be module globals, so the stack can be switched
22 //
23 CONST EFI_DXE_IPL_PPI mDxeIplPpi = {
24 DxeLoadCore
25 };
26
27 CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {
28 CustomGuidedSectionExtract
29 };
30
31 CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {
32 Decompress
33 };
34
35 CONST EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {
36 {
37 EFI_PEI_PPI_DESCRIPTOR_PPI,
38 &gEfiDxeIplPpiGuid,
39 (VOID *) &mDxeIplPpi
40 },
41 {
42 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
43 &gEfiPeiDecompressPpiGuid,
44 (VOID *) &mDecompressPpi
45 }
46 };
47
48 CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi = {
49 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
50 &gEfiEndOfPeiSignalPpiGuid,
51 NULL
52 };
53
54 /**
55 Entry point of DXE IPL PEIM.
56
57 This function installs DXE IPL PPI and Decompress PPI. It also reloads
58 itself to memory on non-S3 resume boot path.
59
60 @param FileHandle Handle of the file being invoked.
61 @param PeiServices Describes the list of possible PEI Services.
62
63 @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
64 @retval Others Some error occurs during the execution of this function.
65
66 **/
67 EFI_STATUS
68 EFIAPI
69 PeimInitializeDxeIpl (
70 IN EFI_PEI_FILE_HANDLE FileHandle,
71 IN CONST EFI_PEI_SERVICES **PeiServices
72 )
73 {
74 EFI_STATUS Status;
75 EFI_BOOT_MODE BootMode;
76 EFI_GUID *ExtractHandlerGuidTable;
77 UINTN ExtractHandlerNumber;
78 EFI_PEI_PPI_DESCRIPTOR *GuidPpi;
79
80 BootMode = GetBootModeHob ();
81
82 if (BootMode != BOOT_ON_S3_RESUME) {
83 Status = PeiServicesRegisterForShadow (FileHandle);
84 if (Status == EFI_SUCCESS) {
85 //
86 // EFI_SUCESS means it is the first time to call register for shadow.
87 //
88 return Status;
89 }
90
91 //
92 // Ensure that DXE IPL is shadowed to permanent memory.
93 //
94 ASSERT (Status == EFI_ALREADY_STARTED);
95
96 //
97 // Get custom extract guided section method guid list
98 //
99 ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);
100
101 //
102 // Install custom extraction guid PPI
103 //
104 if (ExtractHandlerNumber > 0) {
105 GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *) AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));
106 ASSERT (GuidPpi != NULL);
107 while (ExtractHandlerNumber-- > 0) {
108 GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
109 GuidPpi->Ppi = (VOID *) &mCustomGuidedSectionExtractionPpi;
110 GuidPpi->Guid = &ExtractHandlerGuidTable[ExtractHandlerNumber];
111 Status = PeiServicesInstallPpi (GuidPpi++);
112 ASSERT_EFI_ERROR(Status);
113 }
114 }
115
116 }
117
118 //
119 // Install DxeIpl and Decompress PPIs.
120 //
121 Status = PeiServicesInstallPpi (mPpiList);
122 ASSERT_EFI_ERROR(Status);
123
124 return Status;
125 }
126
127 /**
128 Main entry point to last PEIM.
129
130 This function finds DXE Core in the firmware volume and transfer the control to
131 DXE core.
132
133 @param This Entry point for DXE IPL PPI.
134 @param PeiServices General purpose services available to every PEIM.
135 @param HobList Address to the Pei HOB list.
136
137 @return EFI_SUCCESS DXE core was successfully loaded.
138 @return EFI_OUT_OF_RESOURCES There are not enough resources to load DXE core.
139
140 **/
141 EFI_STATUS
142 EFIAPI
143 DxeLoadCore (
144 IN CONST EFI_DXE_IPL_PPI *This,
145 IN EFI_PEI_SERVICES **PeiServices,
146 IN EFI_PEI_HOB_POINTERS HobList
147 )
148 {
149 EFI_STATUS Status;
150 EFI_FV_FILE_INFO DxeCoreFileInfo;
151 EFI_PHYSICAL_ADDRESS DxeCoreAddress;
152 UINT64 DxeCoreSize;
153 EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint;
154 EFI_BOOT_MODE BootMode;
155 EFI_PEI_FILE_HANDLE FileHandle;
156 EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;
157 UINTN DataSize;
158 EFI_MEMORY_TYPE_INFORMATION MemoryData[EfiMaxMemoryType + 1];
159
160 //
161 // if in S3 Resume, restore configure
162 //
163 BootMode = GetBootModeHob ();
164
165 if (BootMode == BOOT_ON_S3_RESUME) {
166 Status = AcpiS3ResumeOs();
167 ASSERT_EFI_ERROR (Status);
168 } else if (BootMode == BOOT_IN_RECOVERY_MODE) {
169 Status = PeiRecoverFirmware ();
170 if (EFI_ERROR (Status)) {
171 DEBUG ((DEBUG_ERROR, "Load Recovery Capsule Failed.(Status = %r)\n", Status));
172 CpuDeadLoop ();
173 }
174
175 //
176 // Now should have a HOB with the DXE core
177 //
178 }
179
180 Status = PeiServicesLocatePpi (
181 &gEfiPeiReadOnlyVariable2PpiGuid,
182 0,
183 NULL,
184 (VOID **)&Variable
185 );
186 if (!EFI_ERROR (Status)) {
187 DataSize = sizeof (MemoryData);
188 Status = Variable->GetVariable (
189 Variable,
190 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
191 &gEfiMemoryTypeInformationGuid,
192 NULL,
193 &DataSize,
194 &MemoryData
195 );
196 if (!EFI_ERROR (Status)) {
197 //
198 // Build the GUID'd HOB for DXE
199 //
200 BuildGuidDataHob (
201 &gEfiMemoryTypeInformationGuid,
202 MemoryData,
203 DataSize
204 );
205 }
206 }
207
208 //
209 // Look in all the FVs present in PEI and find the DXE Core FileHandle
210 //
211 FileHandle = DxeIplFindDxeCore ();
212
213 //
214 // Load the DXE Core from a Firmware Volume, may use LoadFile PPI to do this to save code size.
215 //
216 Status = PeiLoadFile (
217 FileHandle,
218 &DxeCoreAddress,
219 &DxeCoreSize,
220 &DxeCoreEntryPoint
221 );
222 ASSERT_EFI_ERROR (Status);
223
224 //
225 // Get the DxeCore File Info from the FileHandle for the DxeCore GUID file name.
226 //
227 Status = PeiServicesFfsGetFileInfo (FileHandle, &DxeCoreFileInfo);
228 ASSERT_EFI_ERROR (Status);
229
230 //
231 // Add HOB for the DXE Core
232 //
233 BuildModuleHob (
234 &DxeCoreFileInfo.FileName,
235 DxeCoreAddress,
236 ALIGN_VALUE (DxeCoreSize, EFI_PAGE_SIZE),
237 DxeCoreEntryPoint
238 );
239
240 //
241 // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT
242 //
243 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdStatusCodeValuePeiHandoffToDxe));
244
245 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)DxeCoreAddress, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint)));
246
247 //
248 // Transfer control to the DXE Core
249 // The hand off state is simply a pointer to the HOB list
250 //
251 HandOffToDxeCore (DxeCoreEntryPoint, HobList);
252 //
253 // If we get here, then the DXE Core returned. This is an error
254 // DxeCore should not return.
255 //
256 ASSERT (FALSE);
257 CpuDeadLoop ();
258
259 return EFI_OUT_OF_RESOURCES;
260 }
261
262
263 /**
264 Searches DxeCore in all firmware Volumes and loads the first
265 instance that contains DxeCore.
266
267 @return FileHandle of DxeCore to load DxeCore.
268
269 **/
270 EFI_PEI_FILE_HANDLE
271 DxeIplFindDxeCore (
272 VOID
273 )
274 {
275 EFI_STATUS Status;
276 UINTN Instance;
277 EFI_PEI_FV_HANDLE VolumeHandle;
278 EFI_PEI_FILE_HANDLE FileHandle;
279
280 Instance = 0;
281 while (TRUE) {
282 //
283 // Traverse all firmware volume instances
284 //
285 Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);
286 //
287 // If some error occurs here, then we cannot find any firmware
288 // volume that may contain DxeCore.
289 //
290 ASSERT_EFI_ERROR (Status);
291
292 //
293 // Find the DxeCore file type from the beginning in this firmware volume.
294 //
295 FileHandle = NULL;
296 Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle);
297 if (!EFI_ERROR (Status)) {
298 //
299 // Find DxeCore FileHandle in this volume, then we skip other firmware volume and
300 // return the FileHandle.
301 //
302 return FileHandle;
303 }
304 //
305 // We cannot find DxeCore in this firmware volume, then search the next volume.
306 //
307 Instance++;
308 }
309 }
310
311
312 /**
313 Loads and relocates a PE/COFF image into memory.
314
315 @param FileHandle The image file handle
316 @param ImageAddress The base address of the relocated PE/COFF image
317 @param ImageSize The size of the relocated PE/COFF image
318 @param EntryPoint The entry point of the relocated PE/COFF image
319
320 @return EFI_SUCCESS The file was loaded and relocated
321 @return EFI_OUT_OF_RESOURCES There was not enough memory to load and relocate the PE/COFF file
322
323 **/
324 EFI_STATUS
325 PeiLoadFile (
326 IN EFI_PEI_FILE_HANDLE FileHandle,
327 OUT EFI_PHYSICAL_ADDRESS *ImageAddress,
328 OUT UINT64 *ImageSize,
329 OUT EFI_PHYSICAL_ADDRESS *EntryPoint
330 )
331 {
332
333 EFI_STATUS Status;
334 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
335 VOID *Pe32Data;
336
337 //
338 // First try to find the PE32 section in this ffs file.
339 //
340 Status = PeiServicesFfsFindSectionData (
341 EFI_SECTION_PE32,
342 FileHandle,
343 &Pe32Data
344 );
345 if (EFI_ERROR (Status)) {
346 //
347 // NO image types we support so exit.
348 //
349 return Status;
350 }
351
352 ZeroMem (&ImageContext, sizeof (ImageContext));
353 ImageContext.Handle = Pe32Data;
354 ImageContext.ImageRead = PeiImageRead;
355
356
357 Status = PeCoffLoaderGetImageInfo (&ImageContext);
358 if (EFI_ERROR (Status)) {
359 return Status;
360 }
361 //
362 // Allocate Memory for the image
363 //
364 Status = PeiServicesAllocatePages (
365 EfiBootServicesCode,
366 EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize),
367 &ImageContext.ImageAddress
368 );
369 ASSERT_EFI_ERROR (Status);
370 ASSERT (ImageContext.ImageAddress != 0);
371
372 //
373 // Load the image to our new buffer
374 //
375 Status = PeCoffLoaderLoadImage (&ImageContext);
376 if (EFI_ERROR (Status)) {
377 return Status;
378 }
379 //
380 // Relocate the image in our new buffer
381 //
382 Status = PeCoffLoaderRelocateImage (&ImageContext);
383 if (EFI_ERROR (Status)) {
384 return Status;
385 }
386
387 //
388 // Flush the instruction cache so the image data are written before we execute it
389 //
390 InvalidateInstructionCacheRange ((VOID *)(UINTN) ImageContext.ImageAddress, (UINTN) ImageContext.ImageSize);
391
392 *ImageAddress = ImageContext.ImageAddress;
393 *ImageSize = ImageContext.ImageSize;
394 *EntryPoint = ImageContext.EntryPoint;
395
396 return EFI_SUCCESS;
397 }
398
399
400
401
402 /**
403 The ExtractSection() function processes the input section and
404 returns a pointer to the section contents. If the section being
405 extracted does not require processing (if the section
406 GuidedSectionHeader.Attributes has the
407 EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then
408 OutputBuffer is just updated to point to the start of the
409 section's contents. Otherwise, *Buffer must be allocated
410 from PEI permanent memory.
411
412 @param This Indicates the
413 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.
414 Buffer containing the input GUIDed section to be
415 processed. OutputBuffer OutputBuffer is
416 allocated from PEI permanent memory and contains
417 the new section stream.
418 @param InputSection A pointer to the input buffer, which contains
419 the input section to be processed.
420 @param OutputBuffer A pointer to a caller-allocated buffer, whose
421 size is specified by the contents of OutputSize.
422 @param OutputSize A pointer to a caller-allocated
423 UINTN in which the size of *OutputBuffer
424 allocation is stored. If the function
425 returns anything other than EFI_SUCCESS,
426 the value of OutputSize is undefined.
427 @param AuthenticationStatus A pointer to a caller-allocated
428 UINT32 that indicates the
429 authentication status of the
430 output buffer. If the input
431 section's GuidedSectionHeader.
432 Attributes field has the
433 EFI_GUIDED_SECTION_AUTH_STATUS_VALID
434 bit as clear,
435 AuthenticationStatus must return
436 zero. These bits reflect the
437 status of the extraction
438 operation. If the function
439 returns anything other than
440 EFI_SUCCESS, the value of
441 AuthenticationStatus is
442 undefined.
443
444 @retval EFI_SUCCESS The InputSection was
445 successfully processed and the
446 section contents were returned.
447
448 @retval EFI_OUT_OF_RESOURCES The system has insufficient
449 resources to process the request.
450
451 @retval EFI_INVALID_PARAMETER The GUID in InputSection does
452 not match this instance of the
453 GUIDed Section Extraction PPI.
454
455 **/
456 EFI_STATUS
457 EFIAPI
458 CustomGuidedSectionExtract (
459 IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,
460 IN CONST VOID *InputSection,
461 OUT VOID **OutputBuffer,
462 OUT UINTN *OutputSize,
463 OUT UINT32 *AuthenticationStatus
464 )
465 {
466 EFI_STATUS Status;
467 UINT8 *ScratchBuffer;
468 UINT32 ScratchBufferSize;
469 UINT32 OutputBufferSize;
470 UINT16 SectionAttribute;
471
472 //
473 // Init local variable
474 //
475 ScratchBuffer = NULL;
476
477 //
478 // Call GetInfo to get the size and attribute of input guided section data.
479 //
480 Status = ExtractGuidedSectionGetInfo (
481 InputSection,
482 &OutputBufferSize,
483 &ScratchBufferSize,
484 &SectionAttribute
485 );
486
487 if (EFI_ERROR (Status)) {
488 DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));
489 return Status;
490 }
491
492 if (ScratchBufferSize != 0) {
493 //
494 // Allocate scratch buffer
495 //
496 ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));
497 if (ScratchBuffer == NULL) {
498 return EFI_OUT_OF_RESOURCES;
499 }
500 }
501
502 if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && OutputBufferSize > 0) {
503 //
504 // Allocate output buffer
505 //
506 *OutputBuffer = AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize) + 1);
507 if (*OutputBuffer == NULL) {
508 return EFI_OUT_OF_RESOURCES;
509 }
510 DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));
511 //
512 // *OutputBuffer still is one section. Adjust *OutputBuffer offset,
513 // skip EFI section header to make section data at page alignment.
514 //
515 *OutputBuffer = (VOID *)((UINT8 *) *OutputBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER));
516 }
517
518 Status = ExtractGuidedSectionDecode (
519 InputSection,
520 OutputBuffer,
521 ScratchBuffer,
522 AuthenticationStatus
523 );
524 if (EFI_ERROR (Status)) {
525 //
526 // Decode failed
527 //
528 DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));
529 return Status;
530 }
531
532 *OutputSize = (UINTN) OutputBufferSize;
533
534 return EFI_SUCCESS;
535 }
536
537
538
539 /**
540 Decompresses a section to the output buffer.
541
542 This function looks up the compression type field in the input section and
543 applies the appropriate compression algorithm to compress the section to a
544 callee allocated buffer.
545
546 @param This Points to this instance of the
547 EFI_PEI_DECOMPRESS_PEI PPI.
548 @param CompressionSection Points to the compressed section.
549 @param OutputBuffer Holds the returned pointer to the decompressed
550 sections.
551 @param OutputSize Holds the returned size of the decompress
552 section streams.
553
554 @retval EFI_SUCCESS The section was decompressed successfully.
555 OutputBuffer contains the resulting data and
556 OutputSize contains the resulting size.
557
558 **/
559 EFI_STATUS
560 EFIAPI
561 Decompress (
562 IN CONST EFI_PEI_DECOMPRESS_PPI *This,
563 IN CONST EFI_COMPRESSION_SECTION *CompressionSection,
564 OUT VOID **OutputBuffer,
565 OUT UINTN *OutputSize
566 )
567 {
568 EFI_STATUS Status;
569 UINT8 *DstBuffer;
570 UINT8 *ScratchBuffer;
571 UINTN DstBufferSize;
572 UINT32 ScratchBufferSize;
573 EFI_COMMON_SECTION_HEADER *Section;
574 UINTN SectionLength;
575
576 if (CompressionSection->CommonHeader.Type != EFI_SECTION_COMPRESSION) {
577 ASSERT (FALSE);
578 return EFI_INVALID_PARAMETER;
579 }
580
581 Section = (EFI_COMMON_SECTION_HEADER *) CompressionSection;
582 SectionLength = *(UINT32 *) (Section->Size) & 0x00ffffff;
583
584 //
585 // This is a compression set, expand it
586 //
587 switch (CompressionSection->CompressionType) {
588 case EFI_STANDARD_COMPRESSION:
589 if (FeaturePcdGet(PcdDxeIplSupportUefiDecompress)) {
590 //
591 // Load EFI standard compression.
592 // For compressed data, decompress them to destination buffer.
593 //
594 Status = UefiDecompressGetInfo (
595 (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),
596 (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),
597 (UINT32 *) &DstBufferSize,
598 &ScratchBufferSize
599 );
600 if (EFI_ERROR (Status)) {
601 //
602 // GetInfo failed
603 //
604 DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));
605 return EFI_NOT_FOUND;
606 }
607 //
608 // Allocate scratch buffer
609 //
610 ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));
611 if (ScratchBuffer == NULL) {
612 return EFI_OUT_OF_RESOURCES;
613 }
614 //
615 // Allocate destination buffer, extra one page for adjustment
616 //
617 DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);
618 if (DstBuffer == NULL) {
619 return EFI_OUT_OF_RESOURCES;
620 }
621 //
622 // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header
623 // to make section data at page alignment.
624 //
625 DstBuffer = DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);
626 //
627 // Call decompress function
628 //
629 Status = UefiDecompress (
630 (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),
631 DstBuffer,
632 ScratchBuffer
633 );
634 if (EFI_ERROR (Status)) {
635 //
636 // Decompress failed
637 //
638 DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status));
639 return EFI_NOT_FOUND;
640 }
641 break;
642 } else {
643 //
644 // PcdDxeIplSupportUefiDecompress is FALSE
645 // Don't support UEFI decompression algorithm.
646 //
647 ASSERT (FALSE);
648 return EFI_NOT_FOUND;
649 }
650
651 case EFI_NOT_COMPRESSED:
652 //
653 // Allocate destination buffer
654 //
655 DstBufferSize = CompressionSection->UncompressedLength;
656 DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);
657 if (DstBuffer == NULL) {
658 return EFI_OUT_OF_RESOURCES;
659 }
660 //
661 // Adjust DstBuffer offset, skip EFI section header
662 // to make section data at page alignment.
663 //
664 DstBuffer = DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);
665 //
666 // stream is not actually compressed, just encapsulated. So just copy it.
667 //
668 CopyMem (DstBuffer, CompressionSection + 1, DstBufferSize);
669 break;
670
671 default:
672 //
673 // Don't support other unknown compression type.
674 //
675 ASSERT (FALSE);
676 return EFI_NOT_FOUND;
677 }
678
679 *OutputSize = DstBufferSize;
680 *OutputBuffer = DstBuffer;
681
682 return EFI_SUCCESS;
683 }
684
685
686 /**
687 Updates the Stack HOB passed to DXE phase.
688
689 This function traverses the whole HOB list and update the stack HOB to
690 reflect the real stack that is used by DXE core.
691
692 @param BaseAddress The lower address of stack used by DxeCore.
693 @param Length The length of stack used by DxeCore.
694
695 **/
696 VOID
697 UpdateStackHob (
698 IN EFI_PHYSICAL_ADDRESS BaseAddress,
699 IN UINT64 Length
700 )
701 {
702 EFI_PEI_HOB_POINTERS Hob;
703
704 Hob.Raw = GetHobList ();
705 while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
706 if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {
707 //
708 // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type
709 // to be reclaimed by DXE core.
710 //
711 BuildMemoryAllocationHob (
712 Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,
713 Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,
714 EfiConventionalMemory
715 );
716 //
717 // Update the BSP Stack Hob to reflect the new stack info.
718 //
719 Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;
720 Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;
721 break;
722 }
723 Hob.Raw = GET_NEXT_HOB (Hob);
724 }
725 }