1) Initialize gBS, gST, gImageHandle in UefiBootServicesTableLib.c to NULL

2) Add DxeCore infix to the module local variable gBS, gST, gRT, gDS in DxeMain.c. This is to solve the name conflict with UefiBootServicesTableLib which is defined in MDE Library Spec. 
3) Add in check for gBS and gST in UefiDebugLibConOut/DebugLib.c and UefiDebugLibStdErr/DebugLib.c and MdePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c. If they are not initialized, the API will just return with a error message.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2546 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2007-04-06 06:36:47 +00:00
parent 18fda0cec0
commit abb234751e
11 changed files with 82 additions and 74 deletions

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2006, Intel Corporation
Copyright (c) 2006 - 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
@ -116,10 +116,10 @@ typedef struct {
//
// DXE Core Global Variables
//
extern EFI_SYSTEM_TABLE *gST;
extern EFI_BOOT_SERVICES *gBS;
extern EFI_RUNTIME_SERVICES *gRT;
extern EFI_DXE_SERVICES *gDS;
extern EFI_SYSTEM_TABLE *gDxeCoreST;
extern EFI_BOOT_SERVICES *gDxeCoreBS;
extern EFI_RUNTIME_SERVICES *gDxeCoreRT;
extern EFI_DXE_SERVICES *gDxeCoreDS;
extern EFI_HANDLE gDxeCoreImageHandle;
extern EFI_DECOMPRESS_PROTOCOL gEfiDecompress;

View File

@ -211,16 +211,16 @@ EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;
// DXE Core Global Variables for the EFI System Table, Boot Services Table,
// DXE Services Table, and Runtime Services Table
//
EFI_BOOT_SERVICES *gBS = &mBootServices;
EFI_DXE_SERVICES *gDS = &mDxeServices;
EFI_SYSTEM_TABLE *gST = NULL;
EFI_BOOT_SERVICES *gDxeCoreBS = &mBootServices;
EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;
EFI_SYSTEM_TABLE *gDxeCoreST = NULL;
//
// For debug initialize gRT to template. gRT must be allocated from RT memory
// but gRT is used for ASSERT () and DEBUG () type macros so lets give it
// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory
// but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it
// a value that will not cause debug infrastructure to crash early on.
//
EFI_RUNTIME_SERVICES *gRT = &mEfiRuntimeServicesTableTemplate;
EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;
EFI_HANDLE gDxeCoreImageHandle = NULL;
VOID *mHobStart;
@ -288,13 +288,13 @@ Returns:
// Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData
// Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table
//
gST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);
ASSERT (gST != NULL);
gDxeCoreST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);
ASSERT (gDxeCoreST != NULL);
gRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);
ASSERT (gRT != NULL);
gDxeCoreRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);
ASSERT (gDxeCoreRT != NULL);
gST->RuntimeServices = gRT;
gDxeCoreST->RuntimeServices = gDxeCoreRT;
//
// Start the Image Services.
@ -305,7 +305,7 @@ Returns:
//
// Call constructor for all libraries
//
ProcessLibraryConstructorList (gDxeCoreImageHandle, gST);
ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);
PERF_END (0,PEI_TOK, NULL, 0) ;
PERF_START (0,DXE_TOK, NULL, 0) ;
@ -318,7 +318,7 @@ Returns:
//
// Install the DXE Services Table into the EFI System Tables's Configuration Table
//
Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDS);
Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);
ASSERT_EFI_ERROR (Status);
//
@ -400,16 +400,16 @@ Returns:
//
// Produce Firmware Volume Protocols, one for each FV in the HOB list.
//
Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gST);
Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);
ASSERT_EFI_ERROR (Status);
Status = FwVolDriverInit (gDxeCoreImageHandle, gST);
Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);
ASSERT_EFI_ERROR (Status);
//
// Produce the Section Extraction Protocol
//
Status = InitializeSectionExtraction (gDxeCoreImageHandle, gST);
Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);
ASSERT_EFI_ERROR (Status);
//
@ -742,11 +742,11 @@ Returns:
Hdr->CRC32 = 0;
//
// If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
// If gDxeCoreBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
// Crc will come back as zero if we set it to zero here
//
Crc = 0;
gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
gDxeCoreBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
Hdr->CRC32 = Crc;
}
@ -812,24 +812,24 @@ Returns:
//
// Clear the non-runtime values of the EFI System Table
//
gST->BootServices = NULL;
gST->ConIn = NULL;
gST->ConsoleInHandle = NULL;
gST->ConOut = NULL;
gST->ConsoleOutHandle = NULL;
gST->StdErr = NULL;
gST->StandardErrorHandle = NULL;
gDxeCoreST->BootServices = NULL;
gDxeCoreST->ConIn = NULL;
gDxeCoreST->ConsoleInHandle = NULL;
gDxeCoreST->ConOut = NULL;
gDxeCoreST->ConsoleOutHandle = NULL;
gDxeCoreST->StdErr = NULL;
gDxeCoreST->StandardErrorHandle = NULL;
//
// Recompute the 32-bit CRC of the EFI System Table
//
CalculateEfiHdrCrc (&gST->Hdr);
CalculateEfiHdrCrc (&gDxeCoreST->Hdr);
//
// Zero out the Boot Service Table
//
SetMem (gBS, sizeof (EFI_BOOT_SERVICES), 0);
gBS = NULL;
SetMem (gDxeCoreBS, sizeof (EFI_BOOT_SERVICES), 0);
gDxeCoreBS = NULL;
//
// Update the AtRuntime field in Runtiem AP.

View File

@ -181,10 +181,10 @@ Returns:
// It's over kill to do them all every time, but it saves a lot of code.
//
if (Found) {
CalculateEfiHdrCrc (&gRT->Hdr);
CalculateEfiHdrCrc (&gBS->Hdr);
CalculateEfiHdrCrc (&gST->Hdr);
CalculateEfiHdrCrc (&gDS->Hdr);
CalculateEfiHdrCrc (&gDxeCoreRT->Hdr);
CalculateEfiHdrCrc (&gDxeCoreBS->Hdr);
CalculateEfiHdrCrc (&gDxeCoreST->Hdr);
CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);
}
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2006, Intel Corporation
Copyright (c) 2006 - 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
@ -455,7 +455,7 @@ Returns:
Prot = NULL;
Handle = NULL;
ASSERT (NULL != gBS);
ASSERT (NULL != gDxeCoreBS);
if (*UserHandle != NULL_HANDLE) {
Status = CoreHandleProtocol (*UserHandle, Protocol, (VOID **)&ExistingInterface);

View File

@ -132,7 +132,7 @@ Returns:
Image->ImageBasePage = DxeCoreImageBaseAddress;
Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES((UINTN)(DxeCoreImageLength)));
Image->Tpl = gEfiCurrentTpl;
Image->Info.SystemTable = gST;
Image->Info.SystemTable = gDxeCoreST;
Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress;
Image->Info.ImageSize = DxeCoreImageLength;
@ -650,7 +650,7 @@ Returns:
// Initialize the fields for an internal driver
//
Image->Signature = LOADED_IMAGE_PRIVATE_DATA_SIGNATURE;
Image->Info.SystemTable = gST;
Image->Info.SystemTable = gDxeCoreST;
Image->Info.DeviceHandle = DeviceHandle;
Image->Info.Revision = EFI_LOADED_IMAGE_INFORMATION_REVISION;
Image->Info.FilePath = CoreDuplicateDevicePath (FilePath);

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2006, Intel Corporation
Copyright (c) 2006 - 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
@ -97,7 +97,7 @@ Notes:
//
mDebugTable = (EFI_SYSTEM_TABLE_POINTER *)(UINTN)Mem;
mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;
mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gST;
mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gDxeCoreST;
mDebugTable->Crc32 = 0;
Status = CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid, &mDebugInfoTableHeader);
ASSERT_EFI_ERROR (Status);
@ -127,7 +127,7 @@ Returns:
{
ASSERT(mDebugTable != NULL);
mDebugTable->Crc32 = 0;
gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);
gDxeCoreBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);
}
VOID

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2006, Intel Corporation
Copyright (c) 2006 - 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
@ -54,9 +54,9 @@ Returns:
{
UINTN Index;
for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
if (CompareGuid (Guid, &(gST->ConfigurationTable[Index].VendorGuid))) {
*Table = gST->ConfigurationTable[Index].VendorTable;
for (Index = 0; Index < gDxeCoreST->NumberOfTableEntries; Index++) {
if (CompareGuid (Guid, &(gDxeCoreST->ConfigurationTable[Index].VendorGuid))) {
*Table = gDxeCoreST->ConfigurationTable[Index].VendorTable;
return EFI_SUCCESS;
}
}
@ -104,18 +104,18 @@ Returns:
return EFI_INVALID_PARAMETER;
}
EfiConfigurationTable = gST->ConfigurationTable;
EfiConfigurationTable = gDxeCoreST->ConfigurationTable;
//
// Search all the table for an entry that matches Guid
//
for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
if (CompareGuid (Guid, &(gST->ConfigurationTable[Index].VendorGuid))) {
for (Index = 0; Index < gDxeCoreST->NumberOfTableEntries; Index++) {
if (CompareGuid (Guid, &(gDxeCoreST->ConfigurationTable[Index].VendorGuid))) {
break;
}
}
if (Index < gST->NumberOfTableEntries) {
if (Index < gDxeCoreST->NumberOfTableEntries) {
//
// A match was found, so this is either a modify or a delete operation
//
@ -124,22 +124,22 @@ Returns:
// If Table is not NULL, then this is a modify operation.
// Modify the table enty and return.
//
gST->ConfigurationTable[Index].VendorTable = Table;
gDxeCoreST->ConfigurationTable[Index].VendorTable = Table;
return EFI_SUCCESS;
}
//
// A match was found and Table is NULL, so this is a delete operation.
//
gST->NumberOfTableEntries--;
gDxeCoreST->NumberOfTableEntries--;
//
// Copy over deleted entry
//
CopyMem (
&(EfiConfigurationTable[Index]),
&(gST->ConfigurationTable[Index + 1]),
(gST->NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)
&(gDxeCoreST->ConfigurationTable[Index + 1]),
(gDxeCoreST->NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)
);
} else {
@ -156,7 +156,7 @@ Returns:
}
//
// Assume that Index == gST->NumberOfTableEntries
// Assume that Index == gDxeCoreST->NumberOfTableEntries
//
if ((Index * sizeof (EFI_CONFIGURATION_TABLE)) >= mSystemTableAllocateSize) {
//
@ -171,26 +171,26 @@ Returns:
return EFI_OUT_OF_RESOURCES;
}
if (gST->ConfigurationTable != NULL) {
if (gDxeCoreST->ConfigurationTable != NULL) {
//
// Copy the old table to the new table.
//
CopyMem (
EfiConfigurationTable,
gST->ConfigurationTable,
gDxeCoreST->ConfigurationTable,
Index * sizeof (EFI_CONFIGURATION_TABLE)
);
//
// Free Old Table
//
CoreFreePool (gST->ConfigurationTable);
CoreFreePool (gDxeCoreST->ConfigurationTable);
}
//
// Update System Table
//
gST->ConfigurationTable = EfiConfigurationTable;
gDxeCoreST->ConfigurationTable = EfiConfigurationTable;
}
//
@ -202,13 +202,13 @@ Returns:
//
// This is an add operation, so increment the number of table entries
//
gST->NumberOfTableEntries++;
gDxeCoreST->NumberOfTableEntries++;
}
//
// Fix up the CRC-32 in the EFI System Table
//
CalculateEfiHdrCrc (&gST->Hdr);
CalculateEfiHdrCrc (&gDxeCoreST->Hdr);
return EFI_SUCCESS;
}

View File

@ -1,7 +1,7 @@
/** @file
Report Status Code Library for DXE Phase.
Copyright (c) 2006, Intel Corporation<BR>
Copyright (c) 2006 - 2007, Intel Corporation<BR>
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
@ -57,6 +57,9 @@ InternalReportStatusCode (
// in the handle database.
//
if (gStatusCode == NULL) {
if (gBS == NULL) {
return EFI_UNSUPPORTED;
}
Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);
if (EFI_ERROR (Status) || gStatusCode == NULL) {
return EFI_UNSUPPORTED;
@ -476,6 +479,10 @@ ReportStatusCodeEx (
ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
if (gBS == NULL) {
return EFI_UNSUPPORTED;
}
//
// Allocate space for the Status Code Header and its buffer
//

View File

@ -1,7 +1,7 @@
/** @file
UEFI Boot Services Table Library.
Copyright (c) 2006, Intel Corporation<BR>
Copyright (c) 2006 - 2007, Intel Corporation<BR>
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
@ -14,9 +14,9 @@
**/
EFI_HANDLE gImageHandle;
EFI_SYSTEM_TABLE *gST;
EFI_BOOT_SERVICES *gBS;
EFI_HANDLE gImageHandle = NULL;
EFI_SYSTEM_TABLE *gST = NULL;
EFI_BOOT_SERVICES *gBS = NULL;
/**
The constructor function caches the pointer of Boot Services Table.
@ -43,6 +43,7 @@ UefiBootServicesTableLibConstructor (
// Cache the Image Handle
//
gImageHandle = ImageHandle;
ASSERT (gImageHandle != NULL);
//
// Cache pointer to the EFI System Table

View File

@ -1,7 +1,7 @@
/** @file
UEFI Debug Library that uses PrintLib to send messages to CONOUT.
Copyright (c) 2006, Intel Corporation<BR>
Copyright (c) 2006 - 2007, Intel Corporation<BR>
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
@ -65,7 +65,7 @@ DebugPrint (
//
// Send the print string to the Console Output device
//
if (gST->ConOut != NULL) {
if ((gST != NULL) && (gST->ConOut != NULL)) {
gST->ConOut->OutputString (gST->ConOut, Buffer);
}
}
@ -112,7 +112,7 @@ DebugAssert (
//
// Send the print string to the Console Output device
//
if (gST->ConOut != NULL) {
if ((gST != NULL) && (gST->ConOut != NULL)) {
gST->ConOut->OutputString (gST->ConOut, Buffer);
}

View File

@ -1,7 +1,7 @@
/** @file
UEFI Debug Library that uses PrintLib to send messages to STDERR.
Copyright (c) 2006, Intel Corporation<BR>
Copyright (c) 2006 - 2007, Intel Corporation<BR>
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
@ -65,7 +65,7 @@ DebugPrint (
//
// Send the print string to the Standard Error device
//
if (gST->StdErr != NULL) {
if ((gST != NULL) && (gST->StdErr != NULL)) {
gST->StdErr->OutputString (gST->StdErr, Buffer);
}
}
@ -112,7 +112,7 @@ DebugAssert (
//
// Send the print string to the Standard Error device
//
if (gST->StdErr != NULL) {
if ((gST != NULL) && (gST->StdErr != NULL)) {
gST->StdErr->OutputString (gST->StdErr, Buffer);
}