]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmulatorPkg / Library / DxeEmuPeCoffExtraActionLib / DxeEmuPeCoffExtraActionLib.c
1 /** @file
2 Provides services to perform additional actions to relocate and unload
3 PE/Coff image for Emu environment specific purpose such as souce level debug.
4 This version only works for DXE phase
5
6 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
7 Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #include <PiDxe.h>
13
14 #include <Protocol/EmuThunk.h>
15
16 #include <Library/PeCoffLib.h>
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/HobLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/PeCoffExtraActionLib.h>
22
23 //
24 // Cache of UnixThunk protocol
25 //
26 EMU_THUNK_PROTOCOL *mThunk = NULL;
27
28 /**
29 The constructor function gets the pointer of the WinNT thunk functions
30 It will ASSERT() if Unix thunk protocol is not installed.
31
32 @retval EFI_SUCCESS Unix thunk protocol is found and cached.
33
34 **/
35 EFI_STATUS
36 EFIAPI
37 DxeEmuPeCoffLibExtraActionConstructor (
38 IN EFI_HANDLE ImageHandle,
39 IN EFI_SYSTEM_TABLE *SystemTable
40 )
41 {
42 EFI_HOB_GUID_TYPE *GuidHob;
43
44 //
45 // Retrieve EmuThunkProtocol from GUID'ed HOB
46 //
47 GuidHob = GetFirstGuidHob (&gEmuThunkProtocolGuid);
48 ASSERT (GuidHob != NULL);
49 mThunk = (EMU_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
50 ASSERT (mThunk != NULL);
51
52 return EFI_SUCCESS;
53 }
54
55 /**
56 Performs additional actions after a PE/COFF image has been loaded and relocated.
57
58 If ImageContext is NULL, then ASSERT().
59
60 @param ImageContext Pointer to the image context structure that describes the
61 PE/COFF image that has already been loaded and relocated.
62
63 **/
64 VOID
65 EFIAPI
66 PeCoffLoaderRelocateImageExtraAction (
67 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
68 )
69 {
70 if (mThunk != NULL) {
71 mThunk->PeCoffRelocateImageExtraAction (ImageContext);
72 }
73 }
74
75 /**
76 Performs additional actions just before a PE/COFF image is unloaded. Any resources
77 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
78
79 If ImageContext is NULL, then ASSERT().
80
81 @param ImageContext Pointer to the image context structure that describes the
82 PE/COFF image that is being unloaded.
83
84 **/
85 VOID
86 EFIAPI
87 PeCoffLoaderUnloadImageExtraAction (
88 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
89 )
90 {
91 if (mThunk != NULL) {
92 mThunk->PeCoffUnloadImageExtraAction (ImageContext);
93 }
94 }