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/PeiServicesLib.h>
21 #include <Ppi/TemporaryRamSupport.h>
22 #include <Library/PcdLib.h>
23 #include <Library/UefiCpuLib.h>
29 TemporaryRamMigration (
30 IN CONST EFI_PEI_SERVICES
**PeiServices
,
31 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
32 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
36 STATIC TEMPORARY_RAM_SUPPORT_PPI mTempRamSupportPpi
= {
37 (TEMPORARY_RAM_MIGRATION
) TemporaryRamMigration
40 STATIC EFI_PEI_PPI_DESCRIPTOR mPrivateDispatchTable
[] = {
42 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
43 &gEfiTemporaryRamSupportPpiGuid
,
54 IA32_DESCRIPTOR IdtDescriptor
;
56 IdtDescriptor
.Base
= (UINTN
)IdtPtr
;
57 IdtDescriptor
.Limit
= (UINT16
) 0;
58 AsmWriteIdtr (&IdtDescriptor
);
63 SecCoreStartupWithStack (
64 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFirmwareVolumePtr
,
65 IN VOID
*TopOfCurrentStack
68 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
69 UINT8
*BottomOfTempRam
;
73 VOID
*PeiCoreEntryPoint
;
76 // Initialize floating point operating environment
77 // to be compliant with UEFI spec.
79 InitializeFloatingPointUnits ();
82 "SecCoreStartupWithStack(0x%x, 0x%x)\n",
83 (UINT32
)(UINTN
)BootFirmwareVolumePtr
,
84 (UINT32
)(UINTN
)TopOfCurrentStack
87 BottomOfTempRam
= (UINT8
*)(UINTN
) INITIAL_TOP_OF_STACK
;
88 SizeOfTempRam
= (UINTN
) SIZE_64KB
;
89 TopOfTempRam
= BottomOfTempRam
+ SizeOfTempRam
;
98 // |-------------| <---- INITIAL_TOP_OF_STACK
102 // Bind this information into the SEC hand-off state
104 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*)((UINTN
) TopOfTempRam
- SIZE_4KB
);
105 SecCoreData
->DataSize
= sizeof(EFI_SEC_PEI_HAND_OFF
);
107 SecCoreData
->BootFirmwareVolumeBase
= (VOID
*)(UINTN
) PcdGet32 (PcdOvmfFlashFvRecoveryBase
);
108 SecCoreData
->BootFirmwareVolumeSize
= PcdGet32 (PcdOvmfFlashFvRecoverySize
);
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 (BootFirmwareVolumePtr
, &PeiCoreEntryPoint
);
129 if (PeiCoreEntryPoint
!= NULL
) {
131 "Calling PEI Core entry point at 0x%x\n",
135 // Transfer control to the PEI Core
138 (SWITCH_STACK_ENTRY_POINT
) (UINTN
) PeiCoreEntryPoint
,
140 (VOID
*) (UINTN
) ((EFI_PEI_PPI_DESCRIPTOR
*) &mPrivateDispatchTable
),
143 (VOID
*)((UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
)
148 // If we get here, then either we couldn't locate the PEI Core, or
149 // the PEI Core returned.
151 // Both of these errors are unrecoverable.
159 TemporaryRamMigration (
160 IN CONST EFI_PEI_SERVICES
**PeiServices
,
161 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
162 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
166 DEBUG ((EFI_D_ERROR
, "TemporaryRamMigration(0x%x, 0x%x, 0x%x)\n", (UINTN
)TemporaryMemoryBase
, (UINTN
)PermanentMemoryBase
, CopySize
));
169 // Migrate the whole temporary memory to permenent memory.
171 CopyMem((VOID
*)(UINTN
)PermanentMemoryBase
, (VOID
*)(UINTN
)TemporaryMemoryBase
, CopySize
);
174 // SecSwitchStack function must be invoked after the memory migration
175 // immediatly, also we need fixup the stack change caused by new call into
179 (UINTN
) TemporaryMemoryBase
,
180 (UINTN
) PermanentMemoryBase
,