]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/PeiDxePeCoffLoaderLib/PeCoffLoader.c
Fix typo in PeCoffLoaderLib.inf.
[mirror_edk2.git] / MdeModulePkg / Library / PeiDxePeCoffLoaderLib / PeCoffLoader.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 EdkPeCoffLoader.c
15
16 Abstract:
17
18 Wrap the Base PE/COFF loader with the PE COFF Protocol
19
20
21 --*/
22
23 //
24 // The package level header files this module uses
25 //
26 #include <PiPei.h>
27 //
28 // The protocols, PPI and GUID defintions for this module
29 //
30 #include <Guid/PeiPeCoffLoader.h>
31 //
32 // The Library classes this module consumes
33 //
34 #include <Library/PeCoffLib.h>
35
36 #include <IndustryStandard/PeImage.h>
37
38
39 STATIC
40 EFI_STATUS
41 EFIAPI
42 PeCoffLoaderLibGetImageInfo (
43 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
44 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
45 )
46 {
47 EFI_STATUS Status;
48
49 Status = PeCoffLoaderGetImageInfo (ImageContext);
50 if (EFI_ERROR (Status)) {
51 return Status;
52 }
53
54 switch (ImageContext->ImageType) {
55
56 case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
57 ImageContext->ImageCodeMemoryType = EfiLoaderCode;
58 ImageContext->ImageDataMemoryType = EfiLoaderData;
59 break;
60
61 case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
62 ImageContext->ImageCodeMemoryType = EfiBootServicesCode;
63 ImageContext->ImageDataMemoryType = EfiBootServicesData;
64 break;
65
66 case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
67 case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:
68 ImageContext->ImageCodeMemoryType = EfiRuntimeServicesCode;
69 ImageContext->ImageDataMemoryType = EfiRuntimeServicesData;
70 break;
71
72 default:
73 ImageContext->ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;
74 return RETURN_UNSUPPORTED;
75 }
76
77 return Status;
78 }
79
80 STATIC
81 EFI_STATUS
82 EFIAPI
83 PeCoffLoaderLibLoadImage (
84 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
85 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
86 )
87 {
88 return PeCoffLoaderLoadImage (ImageContext);
89 }
90
91 STATIC
92 EFI_STATUS
93 EFIAPI
94 PeCoffLoaderLibRelocateImage (
95 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
96 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
97 )
98 {
99 return PeCoffLoaderRelocateImage (ImageContext);
100 }
101
102 STATIC
103 EFI_STATUS
104 EFIAPI
105 PeCoffLoaderLibUnloadimage (
106 IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
107 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
108 )
109 {
110 return EFI_SUCCESS;
111 }
112
113
114 EFI_PEI_PE_COFF_LOADER_PROTOCOL mPeiEfiPeiPeCoffLoader = {
115 PeCoffLoaderLibGetImageInfo,
116 PeCoffLoaderLibLoadImage,
117 PeCoffLoaderLibRelocateImage,
118 PeCoffLoaderLibUnloadimage
119 };
120
121 EFI_PEI_PE_COFF_LOADER_PROTOCOL *
122 EFIAPI
123 GetPeCoffLoaderProtocol (
124 )
125 {
126 return &mPeiEfiPeiPeCoffLoader;
127 }
128
129