2 Main SEC phase code. Transitions to PEI.
4 Copyright (c) 2008 - 2009, Intel Corporation
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
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.
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/PeimEntryPoint.h>
21 #include <Library/PeiServicesLib.h>
22 #include <Ppi/TemporaryRamSupport.h>
23 #include <Library/PcdLib.h>
24 #include <Library/UefiCpuLib.h>
30 TemporaryRamMigration (
31 IN CONST EFI_PEI_SERVICES
**PeiServices
,
32 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
33 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
37 STATIC TEMPORARY_RAM_SUPPORT_PPI mTempRamSupportPpi
= {
38 (TEMPORARY_RAM_MIGRATION
) TemporaryRamMigration
41 STATIC EFI_PEI_PPI_DESCRIPTOR mPrivateDispatchTable
[] = {
43 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
44 &gEfiTemporaryRamSupportPpiGuid
,
55 IA32_DESCRIPTOR IdtDescriptor
;
57 IdtDescriptor
.Base
= (UINTN
)IdtPtr
;
58 IdtDescriptor
.Limit
= (UINT16
) 0;
59 AsmWriteIdtr (&IdtDescriptor
);
64 SecCoreStartupWithStack (
65 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFv
,
66 IN VOID
*TopOfCurrentStack
69 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
70 UINT8
*BottomOfTempRam
;
74 VOID
*PeiCoreEntryPoint
;
77 "SecCoreStartupWithStack(0x%x, 0x%x)\n",
78 (UINT32
)(UINTN
)BootFv
,
79 (UINT32
)(UINTN
)TopOfCurrentStack
82 ProcessLibraryConstructorList (NULL
, NULL
);
85 // Initialize floating point operating environment
86 // to be compliant with UEFI spec.
88 InitializeFloatingPointUnits ();
90 BottomOfTempRam
= (UINT8
*)(UINTN
) INITIAL_TOP_OF_STACK
;
91 SizeOfTempRam
= (UINTN
) SIZE_64KB
;
92 TopOfTempRam
= BottomOfTempRam
+ SizeOfTempRam
;
101 // |-------------| <---- INITIAL_TOP_OF_STACK
105 // Bind this information into the SEC hand-off state
107 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*)((UINTN
) TopOfTempRam
- SIZE_4KB
);
108 SecCoreData
->DataSize
= sizeof(EFI_SEC_PEI_HAND_OFF
);
110 SecCoreData
->TemporaryRamBase
= (VOID
*) BottomOfTempRam
;
111 SecCoreData
->TemporaryRamSize
= SizeOfTempRam
;
113 SecCoreData
->PeiTemporaryRamSize
= 28 * SIZE_1KB
;
114 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)((UINTN
)SecCoreData
- SecCoreData
->PeiTemporaryRamSize
);
116 SecCoreData
->StackBase
= SecCoreData
->TemporaryRamBase
;
117 SecCoreData
->StackSize
= (UINTN
)SecCoreData
->PeiTemporaryRamBase
- (UINTN
)SecCoreData
->TemporaryRamBase
;
120 // Initialize the IDT Pointer, since IA32 & X64 architectures
121 // use it to store the PEI Services pointer.
123 IdtPtr
= (VOID
*)((UINT8
*)SecCoreData
+ sizeof (*SecCoreData
) + sizeof (UINTN
));
124 IdtPtr
= ALIGN_POINTER(IdtPtr
, 16);
125 InitializeIdtPtr (IdtPtr
);
127 FindPeiCoreEntryPoint (&BootFv
, &PeiCoreEntryPoint
);
129 SecCoreData
->BootFirmwareVolumeBase
= BootFv
;
130 SecCoreData
->BootFirmwareVolumeSize
= (UINTN
) BootFv
->FvLength
;
132 if (PeiCoreEntryPoint
!= NULL
) {
134 "Calling PEI Core entry point at 0x%x\n",
138 // Transfer control to the PEI Core
141 (SWITCH_STACK_ENTRY_POINT
) (UINTN
) PeiCoreEntryPoint
,
143 (VOID
*) (UINTN
) ((EFI_PEI_PPI_DESCRIPTOR
*) &mPrivateDispatchTable
),
146 (VOID
*)((UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
)
151 // If we get here, then either we couldn't locate the PEI Core, or
152 // the PEI Core returned.
154 // Both of these errors are unrecoverable.
162 TemporaryRamMigration (
163 IN CONST EFI_PEI_SERVICES
**PeiServices
,
164 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
165 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
169 DEBUG ((EFI_D_ERROR
, "TemporaryRamMigration(0x%x, 0x%x, 0x%x)\n", (UINTN
)TemporaryMemoryBase
, (UINTN
)PermanentMemoryBase
, CopySize
));
172 // Migrate the whole temporary memory to permenent memory.
174 CopyMem((VOID
*)(UINTN
)PermanentMemoryBase
, (VOID
*)(UINTN
)TemporaryMemoryBase
, CopySize
);
177 // SecSwitchStack function must be invoked after the memory migration
178 // immediatly, also we need fixup the stack change caused by new call into
182 (UINTN
) TemporaryMemoryBase
,
183 (UINTN
) PermanentMemoryBase
,