PI Enabling: the address of PeiServices Pointer should be

1) Set to preceding of IDT table in PeiCore's entry
2) Migrate to preceding of new memory IDT table when memory is discovery

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4059 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
klu2 2007-10-09 08:16:53 +00:00
parent d173d9c761
commit 81c7803cf4
10 changed files with 165 additions and 19 deletions

View File

@ -395,7 +395,8 @@ Returns:
// Migrate IDT from CAR into real memory, so after stack switches to // Migrate IDT from CAR into real memory, so after stack switches to
// the new memory, the caller can get memory version PeiServiceTable. // the new memory, the caller can get memory version PeiServiceTable.
// //
//MigrateIdtTable (PeiServices); MigrateIdtTable (PeiServices);
// //
// Since we are at dispatch level, only the Core's private data // Since we are at dispatch level, only the Core's private data
// is preserved, nobody else should have any data on the stack. // is preserved, nobody else should have any data on the stack.

View File

@ -166,6 +166,11 @@ Returns:
InitializePpiServices (&PrivateData, OldCoreData); InitializePpiServices (&PrivateData, OldCoreData);
//
// Save PeiServicePointer so that it can be retrieved anywhere.
//
SetPeiServicesTablePointer(&PrivateData.PS);
if (OldCoreData != NULL) { if (OldCoreData != NULL) {
PERF_END (NULL,"PreMem", NULL, 0); PERF_END (NULL,"PreMem", NULL, 0);

View File

@ -30,11 +30,29 @@ GetPeiServicesTablePointer (
VOID VOID
); );
/**
The function set the pointer of PEI services immediately preceding the IDT table
according to PI specification.
@param PeiServices The address of PeiServices pointer.
**/
VOID VOID
EFIAPI EFIAPI
SetPeiServicesTablePointer ( SetPeiServicesTablePointer (
EFI_PEI_SERVICES ** PeiServicesTablePointer EFI_PEI_SERVICES ** PeiServicesTablePointer
); );
/**
After memory initialization in PEI phase, the IDT table in temporary memory should
be migrated to memory, and the address of PeiServicesPointer also need to be updated
immediately preceding the new IDT table.
@param PeiServices The address of PeiServices pointer.
**/
VOID
MigrateIdtTable (
IN EFI_PEI_SERVICES **PeiServices
);
#endif #endif

View File

@ -20,6 +20,12 @@
static EFI_PEI_SERVICES **gPeiServices; static EFI_PEI_SERVICES **gPeiServices;
/**
The function set the pointer of PEI services immediately preceding the IDT table
according to PI specification.
@param PeiServices The address of PeiServices pointer.
**/
VOID VOID
EFIAPI EFIAPI
SetPeiServicesTablePointer ( SetPeiServicesTablePointer (
@ -70,3 +76,18 @@ PeiServicesTablePointerLibConstructor (
gPeiServices = PeiServices; gPeiServices = PeiServices;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/**
After memory initialization in PEI phase, the IDT table in temporary memory should
be migrated to memory, and the address of PeiServicesPointer also need to be updated
immediately preceding the new IDT table.
@param PeiServices The address of PeiServices pointer.
**/
VOID
MigrateIdtTable (
IN EFI_PEI_SERVICES **PeiServices
)
{
}

View File

@ -19,15 +19,11 @@
#include <PiPei.h> #include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/PeiServicesTablePointerLib.h> #include <Library/PeiServicesTablePointerLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/BaseMemoryLib.h>
extern
EFI_PEI_SERVICES **
EFIAPI
AsmPeiSevicesTablePointer (
VOID
);
#endif #endif

View File

@ -33,9 +33,66 @@ GetPeiServicesTablePointer (
) )
{ {
EFI_PEI_SERVICES **PeiServices; EFI_PEI_SERVICES **PeiServices;
IA32_DESCRIPTOR Idtr;
PeiServices = (EFI_PEI_SERVICES **) AsmPeiSevicesTablePointer ();
AsmReadIdtr (&Idtr);
PeiServices = (EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - 4));
ASSERT (PeiServices != NULL); ASSERT (PeiServices != NULL);
return PeiServices; return PeiServices;
} }
/**
The function returns the pointer to PeiServicee following
PI1.0.
For IA32, the four-bytes field immediately prior to new IDT
base addres is used to save the EFI_PEI_SERVICES**.
For x64, the eight-bytes field immediately prior to new IDT
base addres is used to save the EFI_PEI_SERVICES**
@retval The pointer to PeiServices.
**/
VOID
EFIAPI
SetPeiServicesTablePointer (
EFI_PEI_SERVICES ** PeiServicesTablePointer
)
{
IA32_DESCRIPTOR Idtr;
AsmReadIdtr (&Idtr);
(*(UINTN*)(Idtr.Base - 4)) = (UINTN)PeiServicesTablePointer;
}
/**
After memory initialization in PEI phase, the IDT table in temporary memory should
be migrated to memory, and the address of PeiServicesPointer also need to be updated
immediately preceding the new IDT table.
@param PeiServices The address of PeiServices pointer.
**/
VOID
MigrateIdtTable (
IN EFI_PEI_SERVICES **PeiServices
)
{
UINTN Size;
VOID *NewBase;
EFI_STATUS Status;
IA32_DESCRIPTOR Idtr;
AsmReadIdtr (&Idtr);
Size = sizeof(UINTN) + (Idtr.Limit + 1);
Status = PeiServicesAllocatePool (Size, &NewBase);
ASSERT_EFI_ERROR (Status);
CopyMem ((VOID*)((UINTN)NewBase + sizeof(UINTN)), (VOID*)Idtr.Base, (Idtr.Limit + 1));
Idtr.Base = (UINTN)NewBase + sizeof(UINTN);
AsmWriteIdtr (&Idtr);
SetPeiServicesTablePointer(PeiServices);
}

View File

@ -31,16 +31,16 @@
[Packages] [Packages]
MdePkg/MdePkg.dec MdePkg/MdePkg.dec
[Sources.Ia32] [Sources]
Ia32/AsmPeiSevicesTablePointer.c|MSFT
Ia32/AsmPeiSevicesTablePointer.S|GCC
PeiServicesTablePointer.c PeiServicesTablePointer.c
InternalPeiServicesTablePointer.h
[Sources.X64]
x64/AsmPeiSevicesTablePointer.asm|MSFT
x64/AsmPeiSevicesTablePointer.S|GCC
PeiServicesTablePointer.c
[LibraryClasses] [LibraryClasses]
DebugLib DebugLib
BaseMemoryLib
PeiServicesLib
BaseLib

View File

@ -62,4 +62,18 @@ PeiServicesTablePointerLibConstructor (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/**
After memory initialization in PEI phase, the IDT table in temporary memory should
be migrated to memory, and the address of PeiServicesPointer also need to be updated
immediately preceding the new IDT table.
@param PeiServices The address of PeiServices pointer.
**/
VOID
MigrateIdtTable (
IN EFI_PEI_SERVICES **PeiServices
)
{
}

View File

@ -21,6 +21,8 @@
#include <Library/PeiServicesTablePointerLib.h> #include <Library/PeiServicesTablePointerLib.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PeiServicesLib.h>
VOID VOID
EFIAPI EFIAPI
@ -75,3 +77,34 @@ PeiServicesTablePointerLibConstructor (
AsmWriteMm7 ((UINT64)(UINTN)PeiServices); AsmWriteMm7 ((UINT64)(UINTN)PeiServices);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/**
After memory initialization in PEI phase, the IDT table in temporary memory should
be migrated to memory, and the address of PeiServicesPointer also need to be updated
immediately preceding the new IDT table.
@param PeiServices The address of PeiServices pointer.
**/
VOID
MigrateIdtTable (
IN EFI_PEI_SERVICES **PeiServices
)
{
UINTN Size;
VOID *NewBase;
EFI_STATUS Status;
IA32_DESCRIPTOR Idtr;
AsmReadIdtr (&Idtr);
Size = Idtr.Limit + 1;
Status = PeiServicesAllocatePool (Size, &NewBase);
ASSERT_EFI_ERROR (Status);
CopyMem (NewBase, (VOID*)Idtr.Base, Size);
Idtr.Base = (UINTN)NewBase;
AsmWriteIdtr (&Idtr);
}

View File

@ -44,4 +44,5 @@
[LibraryClasses] [LibraryClasses]
DebugLib DebugLib
BaseLib BaseLib
BaseMemoryLib
PeiServicesLib