2 Main SEC phase code. Transitions to PEI.
4 Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>
6 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
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.
18 #include <Library/PeimEntryPoint.h>
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/PeiServicesLib.h>
23 #include <Library/PcdLib.h>
24 #include <Library/UefiCpuLib.h>
25 #include <Library/DebugAgentLib.h>
26 #include <Library/IoLib.h>
27 #include <Library/PeCoffLib.h>
28 #include <Library/PeCoffGetEntryPointLib.h>
29 #include <Library/PeCoffExtraActionLib.h>
30 #include <Library/ExtractGuidedSectionLib.h>
31 #include <Library/LocalApicLib.h>
33 #include <Ppi/TemporaryRamSupport.h>
35 #define SEC_IDT_ENTRY_COUNT 34
37 typedef struct _SEC_IDT_TABLE
{
38 EFI_PEI_SERVICES
*PeiService
;
39 IA32_IDT_GATE_DESCRIPTOR IdtTable
[SEC_IDT_ENTRY_COUNT
];
50 TemporaryRamMigration (
51 IN CONST EFI_PEI_SERVICES
**PeiServices
,
52 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
53 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
60 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi
= {
64 EFI_PEI_PPI_DESCRIPTOR mPrivateDispatchTable
[] = {
66 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
67 &gEfiTemporaryRamSupportPpiGuid
,
68 &mTemporaryRamSupportPpi
73 // Template of an IDT entry pointing to 10:FFFFFFE4h.
75 IA32_IDT_GATE_DESCRIPTOR mIdtEntryTemplate
= {
80 IA32_IDT_GATE_TYPE_INTERRUPT_32
, // GateType
86 Locates the main boot firmware volume.
88 @param[in,out] BootFv On input, the base of the BootFv
89 On output, the decompressed main firmware volume
91 @retval EFI_SUCCESS The main firmware volume was located and decompressed
92 @retval EFI_NOT_FOUND The main firmware volume was not found
97 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**BootFv
100 EFI_FIRMWARE_VOLUME_HEADER
*Fv
;
103 ASSERT (((UINTN
) *BootFv
& EFI_PAGE_MASK
) == 0);
106 Distance
= (UINTN
) (*BootFv
)->FvLength
;
108 Fv
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINT8
*) Fv
- EFI_PAGE_SIZE
);
109 Distance
+= EFI_PAGE_SIZE
;
110 if (Distance
> SIZE_32MB
) {
111 return EFI_NOT_FOUND
;
114 if (Fv
->Signature
!= EFI_FVH_SIGNATURE
) {
118 if ((UINTN
) Fv
->FvLength
> Distance
) {
129 Locates a section within a series of sections
130 with the specified section type.
132 The Instance parameter indicates which instance of the section
133 type to return. (0 is first instance, 1 is second...)
135 @param[in] Sections The sections to search
136 @param[in] SizeOfSections Total size of all sections
137 @param[in] SectionType The section type to locate
138 @param[in] Instance The section instance number
139 @param[out] FoundSection The FFS section if found
141 @retval EFI_SUCCESS The file and section was found
142 @retval EFI_NOT_FOUND The file and section was not found
143 @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted
147 FindFfsSectionInstance (
149 IN UINTN SizeOfSections
,
150 IN EFI_SECTION_TYPE SectionType
,
152 OUT EFI_COMMON_SECTION_HEADER
**FoundSection
155 EFI_PHYSICAL_ADDRESS CurrentAddress
;
157 EFI_PHYSICAL_ADDRESS EndOfSections
;
158 EFI_COMMON_SECTION_HEADER
*Section
;
159 EFI_PHYSICAL_ADDRESS EndOfSection
;
162 // Loop through the FFS file sections within the PEI Core FFS file
164 EndOfSection
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) Sections
;
165 EndOfSections
= EndOfSection
+ SizeOfSections
;
167 if (EndOfSection
== EndOfSections
) {
170 CurrentAddress
= (EndOfSection
+ 3) & ~(3ULL);
171 if (CurrentAddress
>= EndOfSections
) {
172 return EFI_VOLUME_CORRUPTED
;
175 Section
= (EFI_COMMON_SECTION_HEADER
*)(UINTN
) CurrentAddress
;
177 Size
= SECTION_SIZE (Section
);
178 if (Size
< sizeof (*Section
)) {
179 return EFI_VOLUME_CORRUPTED
;
182 EndOfSection
= CurrentAddress
+ Size
;
183 if (EndOfSection
> EndOfSections
) {
184 return EFI_VOLUME_CORRUPTED
;
188 // Look for the requested section type
190 if (Section
->Type
== SectionType
) {
192 *FoundSection
= Section
;
200 return EFI_NOT_FOUND
;
204 Locates a section within a series of sections
205 with the specified section type.
207 @param[in] Sections The sections to search
208 @param[in] SizeOfSections Total size of all sections
209 @param[in] SectionType The section type to locate
210 @param[out] FoundSection The FFS section if found
212 @retval EFI_SUCCESS The file and section was found
213 @retval EFI_NOT_FOUND The file and section was not found
214 @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted
218 FindFfsSectionInSections (
220 IN UINTN SizeOfSections
,
221 IN EFI_SECTION_TYPE SectionType
,
222 OUT EFI_COMMON_SECTION_HEADER
**FoundSection
225 return FindFfsSectionInstance (
235 Locates a FFS file with the specified file type and a section
236 within that file with the specified section type.
238 @param[in] Fv The firmware volume to search
239 @param[in] FileType The file type to locate
240 @param[in] SectionType The section type to locate
241 @param[out] FoundSection The FFS section if found
243 @retval EFI_SUCCESS The file and section was found
244 @retval EFI_NOT_FOUND The file and section was not found
245 @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted
249 FindFfsFileAndSection (
250 IN EFI_FIRMWARE_VOLUME_HEADER
*Fv
,
251 IN EFI_FV_FILETYPE FileType
,
252 IN EFI_SECTION_TYPE SectionType
,
253 OUT EFI_COMMON_SECTION_HEADER
**FoundSection
257 EFI_PHYSICAL_ADDRESS CurrentAddress
;
258 EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume
;
259 EFI_FFS_FILE_HEADER
*File
;
261 EFI_PHYSICAL_ADDRESS EndOfFile
;
263 if (Fv
->Signature
!= EFI_FVH_SIGNATURE
) {
264 DEBUG ((EFI_D_ERROR
, "FV at %p does not have FV header signature\n", Fv
));
265 return EFI_VOLUME_CORRUPTED
;
268 CurrentAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) Fv
;
269 EndOfFirmwareVolume
= CurrentAddress
+ Fv
->FvLength
;
272 // Loop through the FFS files in the Boot Firmware Volume
274 for (EndOfFile
= CurrentAddress
+ Fv
->HeaderLength
; ; ) {
276 CurrentAddress
= (EndOfFile
+ 7) & ~(7ULL);
277 if (CurrentAddress
> EndOfFirmwareVolume
) {
278 return EFI_VOLUME_CORRUPTED
;
281 File
= (EFI_FFS_FILE_HEADER
*)(UINTN
) CurrentAddress
;
282 Size
= *(UINT32
*) File
->Size
& 0xffffff;
283 if (Size
< (sizeof (*File
) + sizeof (EFI_COMMON_SECTION_HEADER
))) {
284 return EFI_VOLUME_CORRUPTED
;
287 EndOfFile
= CurrentAddress
+ Size
;
288 if (EndOfFile
> EndOfFirmwareVolume
) {
289 return EFI_VOLUME_CORRUPTED
;
293 // Look for the request file type
295 if (File
->Type
!= FileType
) {
299 Status
= FindFfsSectionInSections (
301 (UINTN
) EndOfFile
- (UINTN
) (File
+ 1),
305 if (!EFI_ERROR (Status
) || (Status
== EFI_VOLUME_CORRUPTED
)) {
312 Locates the compressed main firmware volume and decompresses it.
314 @param[in,out] Fv On input, the firmware volume to search
315 On output, the decompressed BOOT/PEI FV
317 @retval EFI_SUCCESS The file and section was found
318 @retval EFI_NOT_FOUND The file and section was not found
319 @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted
324 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**Fv
328 EFI_GUID_DEFINED_SECTION
*Section
;
329 UINT32 OutputBufferSize
;
330 UINT32 ScratchBufferSize
;
331 UINT16 SectionAttribute
;
332 UINT32 AuthenticationStatus
;
335 EFI_FIRMWARE_VOLUME_IMAGE_SECTION
*FvSection
;
336 EFI_FIRMWARE_VOLUME_HEADER
*PeiMemFv
;
337 EFI_FIRMWARE_VOLUME_HEADER
*DxeMemFv
;
339 FvSection
= (EFI_FIRMWARE_VOLUME_IMAGE_SECTION
*) NULL
;
341 Status
= FindFfsFileAndSection (
343 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
344 EFI_SECTION_GUID_DEFINED
,
345 (EFI_COMMON_SECTION_HEADER
**) &Section
347 if (EFI_ERROR (Status
)) {
348 DEBUG ((EFI_D_ERROR
, "Unable to find GUID defined section\n"));
352 Status
= ExtractGuidedSectionGetInfo (
358 if (EFI_ERROR (Status
)) {
359 DEBUG ((EFI_D_ERROR
, "Unable to GetInfo for GUIDed section\n"));
363 OutputBuffer
= (VOID
*) ((UINT8
*)(UINTN
) PcdGet32 (PcdOvmfDxeMemFvBase
) + SIZE_1MB
);
364 ScratchBuffer
= ALIGN_POINTER ((UINT8
*) OutputBuffer
+ OutputBufferSize
, SIZE_1MB
);
365 Status
= ExtractGuidedSectionDecode (
369 &AuthenticationStatus
371 if (EFI_ERROR (Status
)) {
372 DEBUG ((EFI_D_ERROR
, "Error during GUID section decode\n"));
376 Status
= FindFfsSectionInstance (
379 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
381 (EFI_COMMON_SECTION_HEADER
**) &FvSection
383 if (EFI_ERROR (Status
)) {
384 DEBUG ((EFI_D_ERROR
, "Unable to find PEI FV section\n"));
388 ASSERT (SECTION_SIZE (FvSection
) ==
389 (PcdGet32 (PcdOvmfPeiMemFvSize
) + sizeof (*FvSection
)));
390 ASSERT (FvSection
->Type
== EFI_SECTION_FIRMWARE_VOLUME_IMAGE
);
392 PeiMemFv
= (EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
) PcdGet32 (PcdOvmfPeiMemFvBase
);
393 CopyMem (PeiMemFv
, (VOID
*) (FvSection
+ 1), PcdGet32 (PcdOvmfPeiMemFvSize
));
395 if (PeiMemFv
->Signature
!= EFI_FVH_SIGNATURE
) {
396 DEBUG ((EFI_D_ERROR
, "Extracted FV at %p does not have FV header signature\n", PeiMemFv
));
398 return EFI_VOLUME_CORRUPTED
;
401 Status
= FindFfsSectionInstance (
404 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
406 (EFI_COMMON_SECTION_HEADER
**) &FvSection
408 if (EFI_ERROR (Status
)) {
409 DEBUG ((EFI_D_ERROR
, "Unable to find DXE FV section\n"));
413 ASSERT (FvSection
->Type
== EFI_SECTION_FIRMWARE_VOLUME_IMAGE
);
414 ASSERT (SECTION_SIZE (FvSection
) ==
415 (PcdGet32 (PcdOvmfDxeMemFvSize
) + sizeof (*FvSection
)));
417 DxeMemFv
= (EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
) PcdGet32 (PcdOvmfDxeMemFvBase
);
418 CopyMem (DxeMemFv
, (VOID
*) (FvSection
+ 1), PcdGet32 (PcdOvmfDxeMemFvSize
));
420 if (DxeMemFv
->Signature
!= EFI_FVH_SIGNATURE
) {
421 DEBUG ((EFI_D_ERROR
, "Extracted FV at %p does not have FV header signature\n", DxeMemFv
));
423 return EFI_VOLUME_CORRUPTED
;
431 Locates the PEI Core entry point address
433 @param[in] Fv The firmware volume to search
434 @param[out] PeiCoreEntryPoint The entry point of the PEI Core image
436 @retval EFI_SUCCESS The file and section was found
437 @retval EFI_NOT_FOUND The file and section was not found
438 @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted
442 FindPeiCoreImageBaseInFv (
443 IN EFI_FIRMWARE_VOLUME_HEADER
*Fv
,
444 OUT EFI_PHYSICAL_ADDRESS
*PeiCoreImageBase
448 EFI_COMMON_SECTION_HEADER
*Section
;
450 Status
= FindFfsFileAndSection (
452 EFI_FV_FILETYPE_PEI_CORE
,
456 if (EFI_ERROR (Status
)) {
457 Status
= FindFfsFileAndSection (
459 EFI_FV_FILETYPE_PEI_CORE
,
463 if (EFI_ERROR (Status
)) {
464 DEBUG ((EFI_D_ERROR
, "Unable to find PEI Core image\n"));
469 *PeiCoreImageBase
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)(Section
+ 1);
475 Reads 8-bits of CMOS data.
477 Reads the 8-bits of CMOS data at the location specified by Index.
478 The 8-bit read value is returned.
480 @param Index The CMOS location to read.
482 @return The value read.
491 IoWrite8 (0x70, (UINT8
) Index
);
492 return IoRead8 (0x71);
502 return (CmosRead8 (0xF) == 0xFE);
509 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**PeiFv
512 *PeiFv
= (EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
) PcdGet32 (PcdOvmfPeiMemFvBase
);
518 Locates the PEI Core entry point address
520 @param[in,out] Fv The firmware volume to search
521 @param[out] PeiCoreEntryPoint The entry point of the PEI Core image
523 @retval EFI_SUCCESS The file and section was found
524 @retval EFI_NOT_FOUND The file and section was not found
525 @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted
529 FindPeiCoreImageBase (
530 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**BootFv
,
531 OUT EFI_PHYSICAL_ADDRESS
*PeiCoreImageBase
534 *PeiCoreImageBase
= 0;
537 DEBUG ((EFI_D_VERBOSE
, "SEC: S3 resume\n"));
538 GetS3ResumePeiFv (BootFv
);
540 DEBUG ((EFI_D_VERBOSE
, "SEC: Normal boot\n"));
543 DecompressMemFvs (BootFv
);
546 FindPeiCoreImageBaseInFv (*BootFv
, PeiCoreImageBase
);
550 Find core image base.
555 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFirmwareVolumePtr
,
556 OUT EFI_PHYSICAL_ADDRESS
*SecCoreImageBase
559 EFI_PHYSICAL_ADDRESS CurrentAddress
;
560 EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume
;
561 EFI_FFS_FILE_HEADER
*File
;
563 EFI_PHYSICAL_ADDRESS EndOfFile
;
564 EFI_COMMON_SECTION_HEADER
*Section
;
565 EFI_PHYSICAL_ADDRESS EndOfSection
;
567 *SecCoreImageBase
= 0;
569 CurrentAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) BootFirmwareVolumePtr
;
570 EndOfFirmwareVolume
= CurrentAddress
+ BootFirmwareVolumePtr
->FvLength
;
573 // Loop through the FFS files in the Boot Firmware Volume
575 for (EndOfFile
= CurrentAddress
+ BootFirmwareVolumePtr
->HeaderLength
; ; ) {
577 CurrentAddress
= (EndOfFile
+ 7) & 0xfffffffffffffff8ULL
;
578 if (CurrentAddress
> EndOfFirmwareVolume
) {
579 return EFI_NOT_FOUND
;
582 File
= (EFI_FFS_FILE_HEADER
*)(UINTN
) CurrentAddress
;
583 Size
= *(UINT32
*) File
->Size
& 0xffffff;
584 if (Size
< sizeof (*File
)) {
585 return EFI_NOT_FOUND
;
588 EndOfFile
= CurrentAddress
+ Size
;
589 if (EndOfFile
> EndOfFirmwareVolume
) {
590 return EFI_NOT_FOUND
;
596 if (File
->Type
!= EFI_FV_FILETYPE_SECURITY_CORE
) {
601 // Loop through the FFS file sections within the FFS file
603 EndOfSection
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) (File
+ 1);
605 CurrentAddress
= (EndOfSection
+ 3) & 0xfffffffffffffffcULL
;
606 Section
= (EFI_COMMON_SECTION_HEADER
*)(UINTN
) CurrentAddress
;
608 Size
= *(UINT32
*) Section
->Size
& 0xffffff;
609 if (Size
< sizeof (*Section
)) {
610 return EFI_NOT_FOUND
;
613 EndOfSection
= CurrentAddress
+ Size
;
614 if (EndOfSection
> EndOfFile
) {
615 return EFI_NOT_FOUND
;
619 // Look for executable sections
621 if (Section
->Type
== EFI_SECTION_PE32
|| Section
->Type
== EFI_SECTION_TE
) {
622 if (File
->Type
== EFI_FV_FILETYPE_SECURITY_CORE
) {
623 *SecCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) (Section
+ 1);
630 // SEC Core image found
632 if (*SecCoreImageBase
!= 0) {
639 Find and return Pei Core entry point.
641 It also find SEC and PEI Core file debug inforamtion. It will report them if
642 remote debug is enabled.
646 FindAndReportEntryPoints (
647 IN EFI_FIRMWARE_VOLUME_HEADER
**BootFirmwareVolumePtr
,
648 OUT EFI_PEI_CORE_ENTRY_POINT
*PeiCoreEntryPoint
652 EFI_PHYSICAL_ADDRESS SecCoreImageBase
;
653 EFI_PHYSICAL_ADDRESS PeiCoreImageBase
;
654 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
657 // Find SEC Core and PEI Core image base
659 Status
= FindImageBase (*BootFirmwareVolumePtr
, &SecCoreImageBase
);
660 ASSERT_EFI_ERROR (Status
);
662 FindPeiCoreImageBase (BootFirmwareVolumePtr
, &PeiCoreImageBase
);
664 ZeroMem ((VOID
*) &ImageContext
, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT
));
666 // Report SEC Core debug information when remote debug is enabled
668 ImageContext
.ImageAddress
= SecCoreImageBase
;
669 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) (UINTN
) ImageContext
.ImageAddress
);
670 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
673 // Report PEI Core debug information when remote debug is enabled
675 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)PeiCoreImageBase
;
676 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) (UINTN
) ImageContext
.ImageAddress
);
677 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
680 // Find PEI Core entry point
682 Status
= PeCoffLoaderGetEntryPoint ((VOID
*) (UINTN
) PeiCoreImageBase
, (VOID
**) PeiCoreEntryPoint
);
683 if (EFI_ERROR (Status
)) {
684 *PeiCoreEntryPoint
= 0;
692 SecCoreStartupWithStack (
693 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFv
,
694 IN VOID
*TopOfCurrentStack
697 EFI_SEC_PEI_HAND_OFF SecCoreData
;
698 SEC_IDT_TABLE IdtTableInStack
;
699 IA32_DESCRIPTOR IdtDescriptor
;
702 ProcessLibraryConstructorList (NULL
, NULL
);
705 "SecCoreStartupWithStack(0x%x, 0x%x)\n",
706 (UINT32
)(UINTN
)BootFv
,
707 (UINT32
)(UINTN
)TopOfCurrentStack
711 // Initialize floating point operating environment
712 // to be compliant with UEFI spec.
714 InitializeFloatingPointUnits ();
719 IdtTableInStack
.PeiService
= NULL
;
720 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
721 CopyMem (&IdtTableInStack
.IdtTable
[Index
], &mIdtEntryTemplate
, sizeof (mIdtEntryTemplate
));
724 IdtDescriptor
.Base
= (UINTN
)&IdtTableInStack
.IdtTable
;
725 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
727 AsmWriteIdtr (&IdtDescriptor
);
729 #if defined (MDE_CPU_X64)
731 // ASSERT that the Page Tables were set by the reset vector code to
732 // the address we expect.
734 ASSERT (AsmReadCr3 () == (UINTN
) PcdGet32 (PcdOvmfSecPageTablesBase
));
738 // |-------------| <-- TopOfCurrentStack
742 // |-------------| <-- SecCoreData.TemporaryRamBase
745 ASSERT ((UINTN
) (PcdGet32 (PcdOvmfSecPeiTempRamBase
) +
746 PcdGet32 (PcdOvmfSecPeiTempRamSize
)) ==
747 (UINTN
) TopOfCurrentStack
);
750 // Initialize SEC hand-off state
752 SecCoreData
.DataSize
= sizeof(EFI_SEC_PEI_HAND_OFF
);
754 SecCoreData
.TemporaryRamSize
= (UINTN
) PcdGet32 (PcdOvmfSecPeiTempRamSize
);
755 SecCoreData
.TemporaryRamBase
= (VOID
*)((UINT8
*)TopOfCurrentStack
- SecCoreData
.TemporaryRamSize
);
757 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
758 SecCoreData
.PeiTemporaryRamSize
= SecCoreData
.TemporaryRamSize
>> 1;
760 SecCoreData
.StackBase
= (UINT8
*)SecCoreData
.TemporaryRamBase
+ SecCoreData
.PeiTemporaryRamSize
;
761 SecCoreData
.StackSize
= SecCoreData
.TemporaryRamSize
>> 1;
763 SecCoreData
.BootFirmwareVolumeBase
= BootFv
;
764 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
) BootFv
->FvLength
;
767 // Make sure the 8259 is masked before initializing the Debug Agent and the debug timer is enabled
769 IoWrite8 (0x21, 0xff);
770 IoWrite8 (0xA1, 0xff);
773 // Initialize Local APIC Timer hardware and disable Local APIC Timer
774 // interrupts before initializing the Debug Agent and the debug timer is
777 InitializeApicTimer (0, MAX_UINT32
, TRUE
, 5);
778 DisableApicTimerInterrupt ();
781 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
783 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
787 Caller provided function to be invoked at the end of InitializeDebugAgent().
789 Entry point to the C language phase of SEC. After the SEC assembly
790 code has initialized some temporary memory and set up the stack,
791 the control is transferred to this function.
793 @param[in] Context The first input parameter of InitializeDebugAgent().
802 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
803 EFI_FIRMWARE_VOLUME_HEADER
*BootFv
;
804 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
806 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
809 // Find PEI Core entry point. It will report SEC and Pei Core debug information if remote debug
812 BootFv
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
813 FindAndReportEntryPoints (&BootFv
, &PeiCoreEntryPoint
);
814 SecCoreData
->BootFirmwareVolumeBase
= BootFv
;
815 SecCoreData
->BootFirmwareVolumeSize
= (UINTN
) BootFv
->FvLength
;
818 // Transfer the control to the PEI core
820 (*PeiCoreEntryPoint
) (SecCoreData
, (EFI_PEI_PPI_DESCRIPTOR
*)&mPrivateDispatchTable
);
823 // If we get here then the PEI Core returned, which is not recoverable.
831 TemporaryRamMigration (
832 IN CONST EFI_PEI_SERVICES
**PeiServices
,
833 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
834 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
838 IA32_DESCRIPTOR IdtDescriptor
;
843 DEBUG_AGENT_CONTEXT_POSTMEM_SEC DebugAgentContext
;
845 BASE_LIBRARY_JUMP_BUFFER JumpBuffer
;
848 "TemporaryRamMigration(0x%Lx, 0x%Lx, 0x%Lx)\n",
854 OldHeap
= (VOID
*)(UINTN
)TemporaryMemoryBase
;
855 NewHeap
= (VOID
*)((UINTN
)PermanentMemoryBase
+ (CopySize
>> 1));
857 OldStack
= (VOID
*)((UINTN
)TemporaryMemoryBase
+ (CopySize
>> 1));
858 NewStack
= (VOID
*)(UINTN
)PermanentMemoryBase
;
860 DebugAgentContext
.HeapMigrateOffset
= (UINTN
)NewHeap
- (UINTN
)OldHeap
;
861 DebugAgentContext
.StackMigrateOffset
= (UINTN
)NewStack
- (UINTN
)OldStack
;
863 OldStatus
= SaveAndSetDebugTimerInterrupt (FALSE
);
864 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, (VOID
*) &DebugAgentContext
, NULL
);
869 CopyMem (NewHeap
, OldHeap
, CopySize
>> 1);
874 CopyMem (NewStack
, OldStack
, CopySize
>> 1);
877 // Rebase IDT table in permanent memory
879 AsmReadIdtr (&IdtDescriptor
);
880 IdtDescriptor
.Base
= IdtDescriptor
.Base
- (UINTN
)OldStack
+ (UINTN
)NewStack
;
882 AsmWriteIdtr (&IdtDescriptor
);
885 // Use SetJump()/LongJump() to switch to a new stack.
887 if (SetJump (&JumpBuffer
) == 0) {
888 #if defined (MDE_CPU_IA32)
889 JumpBuffer
.Esp
= JumpBuffer
.Esp
+ DebugAgentContext
.StackMigrateOffset
;
891 #if defined (MDE_CPU_X64)
892 JumpBuffer
.Rsp
= JumpBuffer
.Rsp
+ DebugAgentContext
.StackMigrateOffset
;
894 LongJump (&JumpBuffer
, (UINTN
)-1);
897 SaveAndSetDebugTimerInterrupt (OldStatus
);