summaryrefslogtreecommitdiff
path: root/EdkModulePkg/Core
diff options
context:
space:
mode:
Diffstat (limited to 'EdkModulePkg/Core')
-rw-r--r--EdkModulePkg/Core/Dxe/DxeMain.h43
-rw-r--r--EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c43
-rw-r--r--EdkModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c30
-rw-r--r--EdkModulePkg/Core/Dxe/Event/event.c59
-rw-r--r--EdkModulePkg/Core/Dxe/Event/execdata.c4
-rw-r--r--EdkModulePkg/Core/Dxe/Exec.h3
-rw-r--r--EdkModulePkg/Core/Dxe/Image.h6
-rw-r--r--EdkModulePkg/Core/Dxe/Image/Image.c124
8 files changed, 119 insertions, 193 deletions
diff --git a/EdkModulePkg/Core/Dxe/DxeMain.h b/EdkModulePkg/Core/Dxe/DxeMain.h
index 4ff23f3b0b..28c805703a 100644
--- a/EdkModulePkg/Core/Dxe/DxeMain.h
+++ b/EdkModulePkg/Core/Dxe/DxeMain.h
@@ -130,6 +130,7 @@ extern EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;
extern EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1];
extern BOOLEAN gDispatcherRunning;
+extern EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate;
//
// Service Initialization Functions
@@ -316,27 +317,6 @@ Returns:
;
EFI_STATUS
-CoreShutdownEventServices (
- VOID
- )
-/*++
-
-Routine Description:
-
- Register all runtime events to make sure they are still available after ExitBootService.
-
-Arguments:
-
- None
-
-Returns:
-
- EFI_SUCCESS - Always return success
-
---*/
-;
-
-EFI_STATUS
CoreInitializeImageServices (
IN VOID *HobStart
)
@@ -358,27 +338,6 @@ Returns:
--*/
;
-EFI_STATUS
-CoreShutdownImageServices (
- VOID
- )
-/*++
-
-Routine Description:
-
- Transfer control of runtime images to runtime service
-
-Arguments:
-
- None
-
-Returns:
-
- EFI_SUCCESS - Function successfully returned
-
---*/
-;
-
VOID
CoreNotifyOnArchProtocolInstallation (
VOID
diff --git a/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c b/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c
index 5e5b95af38..6b1f084e77 100644
--- a/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c
+++ b/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c
@@ -157,7 +157,7 @@ EFI_METRONOME_ARCH_PROTOCOL *gMetronome = NULL;
EFI_TIMER_ARCH_PROTOCOL *gTimer = NULL;
EFI_BDS_ARCH_PROTOCOL *gBds = NULL;
EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer = NULL;
-EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = NULL;
+
//
// BugBug: I'n not runtime, but is the PPI?
@@ -324,6 +324,26 @@ EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
#endif
};
+EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
+ INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),
+ INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),
+
+ //
+ // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will
+ // prevent people from having pointer math bugs in their code.
+ // now you have to use *DescriptorSize to make things work.
+ //
+ sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),
+ EFI_MEMORY_DESCRIPTOR_VERSION,
+ 0,
+ NULL,
+ NULL,
+ FALSE,
+ FALSE
+};
+
+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
@@ -886,11 +906,11 @@ CoreExitBootServices (
Routine Description:
- EFI 1.0 API to terminate Boot Services
+ Terminates all boot services.
Arguments:
- ImageHandle - Handle that represents the identity of the calling image
+ ImageHandle - Handle that identifies the exiting image.
MapKey -Key to the latest memory map.
@@ -927,16 +947,6 @@ Returns:
gCpu->DisableInterrupt (gCpu);
//
- // Register Runtime events with the Runtime Architectural Protocol
- //
- CoreShutdownEventServices ();
-
- //
- // Register Runtime images with the Runtime Architectural Protocol
- //
- CoreShutdownImageServices ();
-
- //
// Report that ExitBootServices() has been called
//
// We are using gEfiDxeServicesTableGuid as the caller ID for Dxe Core
@@ -964,7 +974,12 @@ Returns:
//
SetMem (gBS, sizeof (EFI_BOOT_SERVICES), 0);
gBS = NULL;
-
+
+ //
+ // Update the AtRuntime field in Runtiem AP.
+ //
+ gRuntime->AtRuntime = TRUE;
+
return Status;
}
diff --git a/EdkModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c b/EdkModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
index 0ceb82d2c2..a4d653c5aa 100644
--- a/EdkModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
+++ b/EdkModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
@@ -128,6 +128,8 @@ Returns:
ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
VOID *Protocol;
BOOLEAN Found;
+ LIST_ENTRY *Link;
+ LIST_ENTRY TempLinkNode;
Found = FALSE;
for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
@@ -160,6 +162,34 @@ Returns:
// When runtime architectural protocol is available, updates CRC32 in the Debug Table
//
CoreUpdateDebugTableCrc32 ();
+
+ //
+ // Update the Runtime Architectural protocol with the template that the core was
+ // using so there would not need to be a dependency on the Runtime AP
+ //
+
+ //
+ // Copy all the registered Image to new gRuntime protocol
+ //
+ for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {
+ CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
+ InsertTailList (&gRuntime->ImageHead, Link);
+ }
+ //
+ // Copy all the registered Event to new gRuntime protocol
+ //
+ for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {
+ CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
+ InsertTailList (&gRuntime->EventHead, Link);
+ }
+
+ //
+ // Clean up gRuntimeTemplate
+ //
+ gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;
+ gRuntimeTemplate.ImageHead.BackLink = &gRuntimeTemplate.ImageHead;
+ gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;
+ gRuntimeTemplate.EventHead.BackLink = &gRuntimeTemplate.EventHead;
}
}
diff --git a/EdkModulePkg/Core/Dxe/Event/event.c b/EdkModulePkg/Core/Dxe/Event/event.c
index ade810c5c1..08cff427ff 100644
--- a/EdkModulePkg/Core/Dxe/Event/event.c
+++ b/EdkModulePkg/Core/Dxe/Event/event.c
@@ -168,50 +168,6 @@ Returns:
}
-EFI_STATUS
-CoreShutdownEventServices (
- VOID
- )
-/*++
-
-Routine Description:
-
- Register all runtime events to make sure they are still available after ExitBootService.
-
-Arguments:
-
- None
-
-Returns:
-
- EFI_SUCCESS - Always return success.
-
---*/
-{
- LIST_ENTRY *Link;
- IEVENT *Event;
-
- //
- // The Runtime AP is required for the core to function!
- //
- ASSERT (gRuntime != NULL);
-
- for (Link = mRuntimeEventList.ForwardLink; Link != &mRuntimeEventList; Link = Link->ForwardLink) {
- Event = CR (Link, IEVENT, RuntimeLink, EVENT_SIGNATURE);
- gRuntime->RegisterEvent (
- gRuntime,
- Event->Type,
- Event->NotifyTpl,
- Event->NotifyFunction,
- Event->NotifyContext,
- (VOID **)Event
- );
- }
-
- return EFI_SUCCESS;
-}
-
-
VOID
CoreDispatchEventNotifies (
IN EFI_TPL Priority
@@ -559,7 +515,12 @@ Returns:
//
// Keep a list of all RT events so we can tell the RT AP.
//
- InsertTailList (&mRuntimeEventList, &IEvent->RuntimeLink);
+ IEvent->RuntimeData.Type = Type;
+ IEvent->RuntimeData.NotifyTpl = NotifyTpl;
+ IEvent->RuntimeData.NotifyFunction = NotifyFunction;
+ IEvent->RuntimeData.NotifyContext = (VOID *) NotifyContext;
+ IEvent->RuntimeData.Event = (EFI_EVENT *) IEvent;
+ InsertTailList (&gRuntime->EventHead, &IEvent->RuntimeData.Link);
}
CoreAcquireEventLock ();
@@ -835,11 +796,11 @@ Returns:
//
// If the event is queued somewhere, remove it
//
-
- if (Event->RuntimeLink.ForwardLink != NULL) {
- RemoveEntryList (&Event->RuntimeLink);
+
+ if (Event->RuntimeData.Link.ForwardLink != NULL) {
+ RemoveEntryList (&Event->RuntimeData.Link);
}
-
+
if (Event->NotifyLink.ForwardLink != NULL) {
RemoveEntryList (&Event->NotifyLink);
}
diff --git a/EdkModulePkg/Core/Dxe/Event/execdata.c b/EdkModulePkg/Core/Dxe/Event/execdata.c
index e7a11c2400..6e9b68b8be 100644
--- a/EdkModulePkg/Core/Dxe/Event/execdata.c
+++ b/EdkModulePkg/Core/Dxe/Event/execdata.c
@@ -49,7 +49,3 @@ UINTN gEventPending = 0;
//
LIST_ENTRY gEventSignalQueue = INITIALIZE_LIST_HEAD_VARIABLE (gEventSignalQueue);
-//
-// LIST of runtime events that need to be fired by RT AP.
-//
-LIST_ENTRY mRuntimeEventList = INITIALIZE_LIST_HEAD_VARIABLE (mRuntimeEventList);
diff --git a/EdkModulePkg/Core/Dxe/Exec.h b/EdkModulePkg/Core/Dxe/Exec.h
index e7b0f7b660..376c381459 100644
--- a/EdkModulePkg/Core/Dxe/Exec.h
+++ b/EdkModulePkg/Core/Dxe/Exec.h
@@ -56,7 +56,7 @@ typedef struct {
//
// A list of all runtime events
//
- LIST_ENTRY RuntimeLink;
+ EFI_RUNTIME_EVENT_ENTRY RuntimeData;
//
// Information by event type
@@ -204,6 +204,5 @@ extern UINTN gEventPending;
extern LIST_ENTRY gEventQueue[];
extern LIST_ENTRY gEventSignalQueue;
extern UINT8 gHSB[];
-extern LIST_ENTRY mRuntimeEventList;
#endif
diff --git a/EdkModulePkg/Core/Dxe/Image.h b/EdkModulePkg/Core/Dxe/Image.h
index 9d3e41260c..87214d35d5 100644
--- a/EdkModulePkg/Core/Dxe/Image.h
+++ b/EdkModulePkg/Core/Dxe/Image.h
@@ -53,11 +53,9 @@ typedef struct {
EFI_EBC_PROTOCOL *Ebc; // EBC Protocol pointer
- BOOLEAN RuntimeFixupValid; // True if RT image needs fixup
- VOID *RuntimeFixup; // Copy of fixup data;
- LIST_ENTRY Link; // List of RT LOADED_IMAGE_PRIVATE_DATA
+ EFI_RUNTIME_IMAGE_ENTRY *RuntimeData; // Runtime image list
- PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; // PeCoffLoader ImageContext
+ PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; // PeCoffLoader ImageContext
} LOADED_IMAGE_PRIVATE_DATA;
diff --git a/EdkModulePkg/Core/Dxe/Image/Image.c b/EdkModulePkg/Core/Dxe/Image/Image.c
index a71c6f643a..4e6bd0843e 100644
--- a/EdkModulePkg/Core/Dxe/Image/Image.c
+++ b/EdkModulePkg/Core/Dxe/Image/Image.c
@@ -24,11 +24,6 @@ Abstract:
// Module Globals
//
-//
-// LIST of runtime images that need to be relocated.
-//
-LIST_ENTRY mRuntimeImageList = INITIALIZE_LIST_HEAD_VARIABLE (mRuntimeImageList);
-
LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
LOAD_PE32_IMAGE_PRIVATE_DATA mLoadPe32PrivateData = {
@@ -78,9 +73,7 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = {
NULL, // JumpContext
0, // Machine
NULL, // Ebc
- FALSE, // RuntimeFixupValid
- NULL, // RuntimeFixup
- { NULL, NULL }, // Link
+ NULL, // RuntimeData
};
@@ -173,52 +166,6 @@ Returns:
);
}
-
-EFI_STATUS
-CoreShutdownImageServices (
- VOID
- )
-/*++
-
-Routine Description:
-
- Transfer control of runtime images to runtime service
-
-Arguments:
-
- None
-
-Returns:
-
- EFI_SUCCESS - Function successfully returned
-
---*/
-{
- LIST_ENTRY *Link;
- LOADED_IMAGE_PRIVATE_DATA *Image;
-
- //
- // The Runtime AP is required for the core to function!
- //
- ASSERT (gRuntime != NULL);
-
- for (Link = mRuntimeImageList.ForwardLink; Link != &mRuntimeImageList; Link = Link->ForwardLink) {
- Image = CR (Link, LOADED_IMAGE_PRIVATE_DATA, Link, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE);
- if (Image->RuntimeFixupValid) {
- gRuntime->RegisterImage (
- gRuntime,
- (UINT64)(UINTN)(Image->Info.ImageBase),
- (EFI_SIZE_TO_PAGES ((UINTN)Image->Info.ImageSize)),
- Image->RuntimeFixup
- );
- }
- }
-
- return EFI_SUCCESS;
-}
-
-
-
EFI_STATUS
CoreLoadPeImage (
IN VOID *Pe32Handle,
@@ -253,8 +200,9 @@ Returns:
--*/
{
- EFI_STATUS Status;
- UINTN Size;
+ EFI_STATUS Status;
+ BOOLEAN DstBufAlocated;
+ UINTN Size;
ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));
@@ -281,7 +229,7 @@ Returns:
//
// Allocate memory of the correct memory type aligned on the required image boundry
//
-
+ DstBufAlocated = FALSE;
if (DstBuffer == 0) {
//
// Allocate Destination Buffer as caller did not pass it in
@@ -308,8 +256,7 @@ Returns:
if (EFI_ERROR (Status)) {
return Status;
}
-
- Image->ImageBasePage = Image->ImageContext.ImageAddress;
+ DstBufAlocated = TRUE;
} else {
//
@@ -334,9 +281,9 @@ Returns:
Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);
Image->ImageContext.ImageAddress = DstBuffer;
- Image->ImageBasePage = Image->ImageContext.ImageAddress;
}
+ Image->ImageBasePage = Image->ImageContext.ImageAddress;
Image->ImageContext.ImageAddress =
(Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &
~((UINTN)Image->ImageContext.SectionAlignment - 1);
@@ -346,7 +293,7 @@ Returns:
//
Status = gEfiPeiPeCoffLoader->LoadImage (gEfiPeiPeCoffLoader, &Image->ImageContext);
if (EFI_ERROR (Status)) {
- return Status;
+ goto Done;
}
//
@@ -361,13 +308,6 @@ Returns:
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
-
- //
- // Make a list off all the RT images so we can let the RT AP know about them
- //
- Image->RuntimeFixupValid = TRUE;
- Image->RuntimeFixup = Image->ImageContext.FixupData;
- InsertTailList (&mRuntimeImageList, &Image->Link);
}
}
@@ -376,7 +316,7 @@ Returns:
//
Status = gEfiPeiPeCoffLoader->RelocateImage (gEfiPeiPeCoffLoader, &Image->ImageContext);
if (EFI_ERROR (Status)) {
- return Status;
+ goto Done;
}
//
@@ -438,7 +378,23 @@ Returns:
Image->Info.ImageSize = Image->ImageContext.ImageSize;
Image->Info.ImageCodeType = Image->ImageContext.ImageCodeMemoryType;
Image->Info.ImageDataType = Image->ImageContext.ImageDataMemoryType;
-
+ if (Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) {
+ if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {
+ //
+ // Make a list off all the RT images so we can let the RT AP know about them.
+ //
+ Image->RuntimeData = CoreAllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY));
+ if (Image->RuntimeData == NULL) {
+ goto Done;
+ }
+ Image->RuntimeData->ImageBase = Image->Info.ImageBase;
+ Image->RuntimeData->ImageSize = (UINT64) (Image->Info.ImageSize);
+ Image->RuntimeData->RelocationData = Image->ImageContext.FixupData;
+ Image->RuntimeData->Handle = Image->Handle;
+ InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);
+ }
+ }
+
//
// Fill in the entry point of the image if it is available
//
@@ -489,10 +445,19 @@ Returns:
return EFI_SUCCESS;
Done:
+
//
- // Free memory
+ // Free memory.
//
- CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);
+
+ if (DstBufAlocated) {
+ CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);
+ }
+
+ if (Image->ImageContext.FixupData != NULL) {
+ CoreFreePool (Image->ImageContext.FixupData);
+ }
+
return Status;
}
@@ -1168,13 +1133,16 @@ Returns:
);
}
- if (Image->RuntimeFixupValid) {
- //
- // Remove the Image from the Runtime Image list as we are about to Free it!
- //
- RemoveEntryList (&Image->Link);
+ if (Image->RuntimeData != NULL) {
+ if (Image->RuntimeData->Link.ForwardLink != NULL) {
+ //
+ // Remove the Image from the Runtime Image list as we are about to Free it!
+ //
+ RemoveEntryList (&Image->RuntimeData->Link);
+ }
+ CoreFreePool (Image->RuntimeData);
}
-
+
//
// Free the Image from memory
//