From 2df858f7e2d231dd5968a25d32d8a6093e3d9f01 Mon Sep 17 00:00:00 2001 From: mdkinney Date: Sat, 2 Dec 2006 19:09:56 +0000 Subject: [PATCH] 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 --- .../Library/EdkDxeSalLib/EdkDxeSalLib.msa | 3 + .../Library/EdkDxeSalLib/Ipf/EsalServiceLib.c | 55 ++++++++++++++----- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/EdkModulePkg/Library/EdkDxeSalLib/EdkDxeSalLib.msa b/EdkModulePkg/Library/EdkDxeSalLib/EdkDxeSalLib.msa index a7a6214a30..10c3f8cb4f 100644 --- a/EdkModulePkg/Library/EdkDxeSalLib/EdkDxeSalLib.msa +++ b/EdkModulePkg/Library/EdkDxeSalLib/EdkDxeSalLib.msa @@ -54,6 +54,9 @@ EFI_SPECIFICATION_VERSION 0x00020000 EDK_RELEASE_VERSION 0x00020000 + + DxeSalLibConstructor + DxeSalVirtualNotifyEvent diff --git a/EdkModulePkg/Library/EdkDxeSalLib/Ipf/EsalServiceLib.c b/EdkModulePkg/Library/EdkDxeSalLib/Ipf/EsalServiceLib.c index 706dda2873..9eb909dcd3 100644 --- a/EdkModulePkg/Library/EdkDxeSalLib/Ipf/EsalServiceLib.c +++ b/EdkModulePkg/Library/EdkDxeSalLib/Ipf/EsalServiceLib.c @@ -19,25 +19,21 @@ Abstract: #include -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. @@ -47,8 +43,11 @@ DxeSalLibConstruct ( // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it // 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); + Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, &mEsalBootService); + 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