Remove use of global variable at runtime in this lib

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2046 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
mdkinney 2006-12-02 19:09:56 +00:00
parent 22613d6e71
commit 2df858f7e2
2 changed files with 45 additions and 13 deletions

View File

@ -54,6 +54,9 @@
<Externs>
<Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
<Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
<Extern>
<Constructor>DxeSalLibConstructor</Constructor>
</Extern>
<Extern>
<SetVirtualAddressMapCallBack>DxeSalVirtualNotifyEvent</SetVirtualAddressMapCallBack>
</Extern>

View File

@ -19,25 +19,21 @@ Abstract:
#include <Ipf/IpfDefines.h>
BOOLEAN mLibraryInitialized = FALSE;
STATIC EXTENDED_SAL_BOOT_SERVICE_PROTOCOL *mEsalBootService;
STATIC EFI_PLABEL mPlabel;
EXTENDED_SAL_BOOT_SERVICE_PROTOCOL *mEsalBootService = NULL;
EFI_PLABEL mPlabel;
EFI_STATUS
EFIAPI
DxeSalLibConstruct (
// IN EFI_HANDLE ImageHandle,
// IN EFI_SYSTEM_TABLE *SystemTable
DxeSalLibInitialize (
VOID
)
{
EFI_PLABEL *Plabel;
EFI_STATUS Status;
if (mLibraryInitialized == TRUE) {
if (mEsalBootService != NULL) {
return EFI_SUCCESS;
}
mLibraryInitialized = TRUE;
//
// The protocol contains a function pointer, which is an indirect procedure call.
@ -48,7 +44,10 @@ DxeSalLibConstruct (
// away. We cache it in a module global, so we can register the vitrual version.
//
Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, &mEsalBootService);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
mEsalBootService = NULL;
return EFI_SUCCESS;
}
Plabel = (EFI_PLABEL *) (UINTN) mEsalBootService->ExtendedSalProc;
@ -56,7 +55,17 @@ DxeSalLibConstruct (
mPlabel.GP = Plabel->GP;
SetEsalPhysicalEntryPoint (mPlabel.EntryPoint, mPlabel.GP);
return Status;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
DxeSalLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return DxeSalLibInitialize ();
}
VOID
@ -115,7 +124,7 @@ Returns:
--*/
{
DxeSalLibConstruct ();
DxeSalLibInitialize ();
return mEsalBootService->AddExtendedSalProc (
mEsalBootService,
ClassGuid,
@ -224,12 +233,32 @@ Returns:
SAL_RETURN_REGS ReturnReg;
SAL_EXTENDED_SAL_PROC EsalProc;
DxeSalLibConstruct ();
ReturnReg = GetEsalEntryPoint ();
if (ReturnReg.Status != EFI_SAL_SUCCESS) {
return ReturnReg;
}
//
// Look at the physical mode ESAL entry point to determine of the ESAL entry point has been initialized
//
if (*(UINT64 *)ReturnReg.r9 == 0 && *(UINT64 *)(ReturnReg.r9 + 8) == 0) {
//
// Both the function ponter and the GP value are zero, so attempt to initialize the ESAL Entry Point
//
DxeSalLibInitialize ();
ReturnReg = GetEsalEntryPoint ();
if (ReturnReg.Status != EFI_SAL_SUCCESS) {
return ReturnReg;
}
if (*(UINT64 *)ReturnReg.r9 == 0 && *(UINT64 *)(ReturnReg.r9 + 8) == 0) {
//
// The ESAL Entry Point could not be initialized
//
ReturnReg.Status = EFI_SAL_ERROR;
return ReturnReg;
}
}
if (ReturnReg.r11 & PSR_IT_MASK) {
//
// Virtual mode plabel to entry point