summaryrefslogtreecommitdiff
path: root/Nt32Pkg/Sec
diff options
context:
space:
mode:
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>2008-02-29 18:24:43 +0000
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>2008-02-29 18:24:43 +0000
commit58dcdada561c36394c819d3105e867208b84227d (patch)
tree8e3b31896fffa7004a608746d8b99806ce3f1631 /Nt32Pkg/Sec
parentbc4cb041a3236518393b1ca475a3069b128fb88a (diff)
downloadedk2-platforms-58dcdada561c36394c819d3105e867208b84227d.tar.xz
Merge Temporary Ram support patch.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4782 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Nt32Pkg/Sec')
-rw-r--r--Nt32Pkg/Sec/SecMain.c85
-rw-r--r--Nt32Pkg/Sec/SecMain.h9
-rw-r--r--Nt32Pkg/Sec/SecMain.inf6
-rw-r--r--Nt32Pkg/Sec/Stack.asm94
4 files changed, 183 insertions, 11 deletions
diff --git a/Nt32Pkg/Sec/SecMain.c b/Nt32Pkg/Sec/SecMain.c
index 4054d61bd0..ccfc6bb3f8 100644
--- a/Nt32Pkg/Sec/SecMain.c
+++ b/Nt32Pkg/Sec/SecMain.c
@@ -58,6 +58,7 @@ EFI_PEI_PROGRESS_CODE_PPI mSecStatusCodePpi = { SecPeiReport
NT_FWH_PPI mSecFwhInformationPpi = { SecWinNtFdAddress };
+TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};
EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {
{
@@ -86,6 +87,11 @@ EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {
&mSecStatusCodePpi
},
{
+ EFI_PEI_PPI_DESCRIPTOR_PPI,
+ &gEfiTemporaryRamSupportPpiGuid,
+ &mSecTemporaryRamSupportPpi
+ },
+ {
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gNtFwhPpiGuid,
&mSecFwhInformationPpi
@@ -116,7 +122,12 @@ UINTN mPdbNameModHandleArraySize = 0;
PDB_NAME_TO_MOD_HANDLE *mPdbNameModHandleArray = NULL;
-
+VOID
+EFIAPI
+SecSwitchStack (
+ UINT32 TemporaryMemoryBase,
+ UINT32 PermenentMemoryBase
+ );
INTN
EFIAPI
@@ -566,18 +577,31 @@ Returns:
EFI_PHYSICAL_ADDRESS PeiCoreEntryPoint;
EFI_PHYSICAL_ADDRESS PeiImageAddress;
EFI_SEC_PEI_HAND_OFF *SecCoreData;
+ UINTN PeiStackSize;
//
// Compute Top Of Memory for Stack and PEI Core Allocations
//
- TopOfMemory = LargestRegion + LargestRegionSize;
+ TopOfMemory = LargestRegion + LargestRegionSize;
+ PeiStackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);
//
- // Allocate 128KB for the Stack
+ // |-----------| <---- TemporaryRamBase + TemporaryRamSize
+ // | Heap |
+ // | |
+ // |-----------| <---- StackBase / PeiTemporaryMemoryBase
+ // | |
+ // | Stack |
+ // |-----------| <---- TemporaryRamBase
+ //
+ TopOfStack = (VOID *)(LargestRegion + PeiStackSize);
+ TopOfMemory = LargestRegion + PeiStackSize;
+
//
- TopOfStack = (VOID *)((UINTN)TopOfMemory - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);
+ // Reservet space for storing PeiCore's parament in stack.
+ //
+ TopOfStack = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
- TopOfMemory = TopOfMemory - STACK_SIZE;
//
// Patch value in dispatch table values
@@ -591,12 +615,12 @@ Returns:
SecCoreData->DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);
SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase;
SecCoreData->BootFirmwareVolumeSize = FixedPcdGet32(PcdWinNtFirmwareFdSize);
- SecCoreData->TemporaryRamBase = (VOID*)(UINTN)TopOfMemory;
+ SecCoreData->TemporaryRamBase = (VOID*)(UINTN)LargestRegion;
SecCoreData->TemporaryRamSize = STACK_SIZE;
- SecCoreData->PeiTemporaryRamBase = SecCoreData->TemporaryRamBase;
- SecCoreData->PeiTemporaryRamSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);
- SecCoreData->StackBase = (VOID*)((UINTN)SecCoreData->TemporaryRamBase + (UINTN)SecCoreData->TemporaryRamSize);
- SecCoreData->StackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);
+ SecCoreData->StackBase = (VOID*) ((UINTN) SecCoreData->TemporaryRamBase + PeiStackSize);
+ SecCoreData->StackSize = PeiStackSize;
+ SecCoreData->PeiTemporaryRamBase = SecCoreData->StackBase;
+ SecCoreData->PeiTemporaryRamSize = STACK_SIZE - PeiStackSize;
//
// Load the PEI Core from a Firmware Volume
@@ -1209,3 +1233,44 @@ _ModuleEntryPoint (
{
}
+EFI_STATUS
+EFIAPI
+SecTemporaryRamSupport (
+ IN CONST EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
+ IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
+ IN UINTN CopySize
+ )
+{
+ //
+ // Migrate the whole temporary memory to permenent memory.
+ //
+ CopyMem (
+ (VOID*)(UINTN)PermanentMemoryBase,
+ (VOID*)(UINTN)TemporaryMemoryBase,
+ CopySize
+ );
+
+ //
+ // SecSwitchStack function must be invoked after the memory migration
+ // immediatly, also we need fixup the stack change caused by new call into
+ // permenent memory.
+ //
+ SecSwitchStack (
+ (UINT32) TemporaryMemoryBase,
+ (UINT32) PermanentMemoryBase
+ );
+
+ //
+ // We need *not* fix the return address because currently,
+ // The PeiCore is excuted in flash.
+ //
+
+ //
+ // Simulate to invalid CAR, terminate CAR
+ //
+ //ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);
+
+ return EFI_SUCCESS;
+}
+
diff --git a/Nt32Pkg/Sec/SecMain.h b/Nt32Pkg/Sec/SecMain.h
index 7102d5f5fa..1f54fd0dd2 100644
--- a/Nt32Pkg/Sec/SecMain.h
+++ b/Nt32Pkg/Sec/SecMain.h
@@ -31,6 +31,7 @@ Abstract:
#include <Ppi/NtThunk.h>
#include <Ppi/StatusCode.h>
#include <Ppi/NtFwh.h>
+#include <Ppi/TemporaryRamSupport.h>
#include <Library/PcdLib.h>
#include <Library/DebugLib.h>
#include <Library/PrintLib.h>
@@ -576,6 +577,14 @@ SecNt32PeCoffUnloadimage (
IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
);
+EFI_STATUS
+EFIAPI
+SecTemporaryRamSupport (
+ IN CONST EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
+ IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
+ IN UINTN CopySize
+ );
typedef struct {
EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff;
diff --git a/Nt32Pkg/Sec/SecMain.inf b/Nt32Pkg/Sec/SecMain.inf
index 20e4726465..95cd30e2ea 100644
--- a/Nt32Pkg/Sec/SecMain.inf
+++ b/Nt32Pkg/Sec/SecMain.inf
@@ -33,6 +33,7 @@
WinNtThunk.c
FwVol.c
SecMain.c
+ Stack.asm
[Packages]
MdePkg/MdePkg.dec
@@ -58,6 +59,7 @@
gNtFwhPpiGuid # PPI ALWAYS_PRODUCED
gPeiNtAutoScanPpiGuid # PPI ALWAYS_PRODUCED
gPeiNtThunkPpiGuid # PPI ALWAYS_PRODUCED
+ gEfiTemporaryRamSupportPpiGuid
[FixedPcd.common]
@@ -69,4 +71,6 @@
[BuildOptions.common]
MSFT:*_*_IA32_DLINK_FLAGS = /out:"$(BIN_DIR)\SecMain.exe" /base:0x10000000 /pdb:"$(BIN_DIR)\SecMain.pdb" /LIBPATH:"$(VCINSTALLDIR)\Lib" /LIBPATH:"$(VCINSTALLDIR)\PlatformSdk\Lib" /NOLOGO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP /OPT:REF /DEBUG /MACHINE:I386 /LTCG Kernel32.lib MSVCRTD.lib Gdi32.lib User32.lib Winmm.lib
MSFT:*_*_IA32_CC_FLAGS = /nologo /W4 /WX /Gy /c /D UNICODE /Od /FI$(DEST_DIR_DEBUG)/AutoGen.h /EHs-c- /GF /Gs8192 /Zi /Gm /D _CRT_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_DEPRECATE
-
+ MSFT:*_*_IA32_PP_FLAGS = /nologo /E /TC /FI$(DEST_DIR_DEBUG)/AutoGen.h
+ MSFT:*_*_IA32_ASM_FLAGS = /nologo /W3 /WX /c /coff /Cx /Zd /W0 /Zi
+ MSFT:*_*_IA32_ASMLINK_FLAGS = /link /nologo /tiny
diff --git a/Nt32Pkg/Sec/Stack.asm b/Nt32Pkg/Sec/Stack.asm
new file mode 100644
index 0000000000..ca6b7faaaa
--- /dev/null
+++ b/Nt32Pkg/Sec/Stack.asm
@@ -0,0 +1,94 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2007, Intel Corporation
+; All rights reserved. This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution. The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+; Stack.asm
+;
+; Abstract:
+;
+; Switch the stack from temporary memory to permenent memory.
+;
+;------------------------------------------------------------------------------
+
+ .586p
+ .model flat,C
+ .code
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; SecSwitchStack (
+; UINT32 TemporaryMemoryBase,
+; UINT32 PermenentMemoryBase
+; );
+;------------------------------------------------------------------------------
+SecSwitchStack PROC
+ ;
+ ; Save three register: eax, ebx, ecx
+ ;
+ push eax
+ push ebx
+ push ecx
+ push edx
+
+ ;
+ ; !!CAUTION!! this function address's is pushed into stack after
+ ; migration of whole temporary memory, so need save it to permenent
+ ; memory at first!
+ ;
+
+ mov ebx, [esp + 20] ; Save the first parameter
+ mov ecx, [esp + 24] ; Save the second parameter
+
+ ;
+ ; Save this function's return address into permenent memory at first.
+ ; Then, Fixup the esp point to permenent memory
+ ;
+ mov eax, esp
+ sub eax, ebx
+ add eax, ecx
+ mov edx, dword ptr [esp] ; copy pushed register's value to permenent memory
+ mov dword ptr [eax], edx
+ mov edx, dword ptr [esp + 4]
+ mov dword ptr [eax + 4], edx
+ mov edx, dword ptr [esp + 8]
+ mov dword ptr [eax + 8], edx
+ mov edx, dword ptr [esp + 12]
+ mov dword ptr [eax + 12], edx
+ mov edx, dword ptr [esp + 16] ; Update this function's return address into permenent memory
+ mov dword ptr [eax + 16], edx
+ mov esp, eax ; From now, esp is pointed to permenent memory
+
+ ;
+ ; Fixup the ebp point to permenent memory
+ ;
+ mov eax, ebp
+ sub eax, ebx
+ add eax, ecx
+ mov ebp, eax ; From now, ebp is pointed to permenent memory
+
+ ;
+ ; Fixup callee's ebp point for PeiDispatch
+ ;
+ mov eax, dword ptr [ebp]
+ sub eax, ebx
+ add eax, ecx
+ mov dword ptr [ebp], eax ; From now, Temporary's PPI caller's stack is in permenent memory
+
+ pop edx
+ pop ecx
+ pop ebx
+ pop eax
+ ret
+SecSwitchStack ENDP
+
+ END