]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/EfiLdr/PeLoader.c
Add missing module for duet package.
[mirror_edk2.git] / DuetPkg / EfiLdr / PeLoader.c
1 /*++
2
3 Copyright (c) 2006, 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 PeLoader.c
14
15 Abstract:
16
17 Revision History:
18
19 --*/
20 #include "EfiLdr.h"
21 #include "Debug.h"
22 #include "Support.h"
23
24 STATIC
25 EFI_STATUS
26 EfiLdrPeCoffLoadPeRelocate (
27 IN EFILDR_LOADED_IMAGE *Image,
28 IN EFI_IMAGE_DATA_DIRECTORY *RelocDir,
29 IN UINTN Adjust,
30 IN UINTN *NumberOfMemoryMapEntries,
31 IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor
32 );
33
34 STATIC
35 EFI_STATUS
36 EfiLdrPeCoffImageRead (
37 IN VOID *FHand,
38 IN UINTN Offset,
39 IN OUT UINTN ReadSize,
40 OUT VOID *Buffer
41 );
42
43 STATIC
44 VOID *
45 EfiLdrPeCoffImageAddress (
46 IN EFILDR_LOADED_IMAGE *Image,
47 IN UINTN Address
48 );
49
50
51 EFI_STATUS
52 EfiLdrPeCoffSetImageType (
53 IN OUT EFILDR_LOADED_IMAGE *Image,
54 IN UINTN ImageType
55 );
56
57 EFI_STATUS
58 EfiLdrPeCoffCheckImageMachineType (
59 IN UINT16 MachineType
60 );
61
62 EFI_STATUS
63 EfiLdrGetPeImageInfo (
64 IN VOID *FHand,
65 OUT UINT64 *ImageBase,
66 OUT UINT32 *ImageSize
67 )
68 {
69 EFI_STATUS Status;
70 EFI_IMAGE_DOS_HEADER DosHdr;
71 EFI_IMAGE_OPTIONAL_HEADER_UNION PeHdr;
72
73 ZeroMem (&DosHdr, sizeof(DosHdr));
74 ZeroMem (&PeHdr, sizeof(PeHdr));
75
76 //
77 // Read image headers
78 //
79
80 EfiLdrPeCoffImageRead (FHand, 0, sizeof(DosHdr), &DosHdr);
81 if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
82 return EFI_UNSUPPORTED;
83 }
84
85 EfiLdrPeCoffImageRead (FHand, DosHdr.e_lfanew, sizeof(PeHdr), &PeHdr);
86
87 if (PeHdr.Pe32.Signature != EFI_IMAGE_NT_SIGNATURE) {
88 return EFI_UNSUPPORTED;
89 }
90
91 //
92 // Verify machine type
93 //
94
95 Status = EfiLdrPeCoffCheckImageMachineType (PeHdr.Pe32.FileHeader.Machine);
96 if (EFI_ERROR(Status)) {
97 return Status;
98 }
99
100 if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
101 *ImageBase = (UINT32)PeHdr.Pe32.OptionalHeader.ImageBase;
102 } else if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
103 *ImageBase = PeHdr.Pe32Plus.OptionalHeader.ImageBase;
104 } else {
105 return EFI_UNSUPPORTED;
106 }
107
108 *ImageSize = PeHdr.Pe32.OptionalHeader.SizeOfImage;
109
110 return EFI_SUCCESS;
111 }
112
113 EFI_STATUS
114 EfiLdrPeCoffLoadPeImage (
115 IN VOID *FHand,
116 IN EFILDR_LOADED_IMAGE *Image,
117 IN UINTN *NumberOfMemoryMapEntries,
118 IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor
119 )
120 {
121 EFI_IMAGE_DOS_HEADER DosHdr;
122 EFI_IMAGE_OPTIONAL_HEADER_UNION PeHdr;
123 EFI_IMAGE_SECTION_HEADER *FirstSection;
124 EFI_IMAGE_SECTION_HEADER *Section;
125 UINTN Index;
126 EFI_STATUS Status;
127 UINT8 *Base;
128 UINT8 *End;
129 EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
130 UINTN DirCount;
131 EFI_IMAGE_DEBUG_DIRECTORY_ENTRY TempDebugEntry;
132 EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;
133 UINTN CodeViewSize;
134 UINTN CodeViewOffset;
135 UINTN CodeViewFileOffset;
136 UINTN OptionalHeaderSize;
137 UINTN PeHeaderSize;
138 UINT32 NumberOfRvaAndSizes;
139 EFI_IMAGE_DATA_DIRECTORY *DataDirectory;
140 UINT64 ImageBase;
141
142 ZeroMem (&DosHdr, sizeof(DosHdr));
143 ZeroMem (&PeHdr, sizeof(PeHdr));
144
145 //
146 // Read image headers
147 //
148
149 EfiLdrPeCoffImageRead (FHand, 0, sizeof(DosHdr), &DosHdr);
150 if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
151 // DEBUG ((D_LOAD, "PeCoffLoadPeImage: Dos header signature not found\n"));
152 PrintHeader ('F');
153 return EFI_UNSUPPORTED;
154 }
155
156 EfiLdrPeCoffImageRead (FHand, DosHdr.e_lfanew, sizeof(PeHdr), &PeHdr);
157
158 if (PeHdr.Pe32.Signature != EFI_IMAGE_NT_SIGNATURE) {
159 // DEBUG ((D_LOAD, "PeCoffLoadPeImage: PE image header signature not found\n"));
160 PrintHeader ('G');
161 return EFI_UNSUPPORTED;
162 }
163
164 //
165 // Set the image subsystem type
166 //
167
168 Status = EfiLdrPeCoffSetImageType (Image, PeHdr.Pe32.OptionalHeader.Subsystem);
169 if (EFI_ERROR(Status)) {
170 // DEBUG ((D_LOAD, "PeCoffLoadPeImage: Subsystem type not known\n"));
171 PrintHeader ('H');
172 return Status;
173 }
174
175 //
176 // Verify machine type
177 //
178
179 Status = EfiLdrPeCoffCheckImageMachineType (PeHdr.Pe32.FileHeader.Machine);
180 if (EFI_ERROR(Status)) {
181 // DEBUG ((D_LOAD, "PeCoffLoadPeImage: Incorrect machine type\n"));
182 PrintHeader ('I');
183 return Status;
184 }
185
186 //
187 // Compute the amount of memory needed to load the image and
188 // allocate it. This will include all sections plus the codeview debug info.
189 // Since the codeview info is actually outside of the image, we calculate
190 // its size seperately and add it to the total.
191 //
192 // Memory starts off as data
193 //
194
195 CodeViewSize = 0;
196 CodeViewFileOffset = 0;
197 if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
198 DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(PeHdr.Pe32.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
199 } else if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
200 DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(PeHdr.Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
201 } else {
202 return EFI_UNSUPPORTED;
203 }
204 for (DirCount = 0;
205 (DirCount < DirectoryEntry->Size / sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) && (CodeViewSize == 0);
206 DirCount++) {
207 Status = EfiLdrPeCoffImageRead (
208 FHand,
209 DirectoryEntry->VirtualAddress + DirCount * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY),
210 sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY),
211 &TempDebugEntry
212 );
213 if (!EFI_ERROR (Status)) {
214 if (TempDebugEntry.Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
215 CodeViewSize = TempDebugEntry.SizeOfData;
216 CodeViewFileOffset = TempDebugEntry.FileOffset;
217 }
218 }
219 }
220
221 CodeViewOffset = PeHdr.Pe32.OptionalHeader.SizeOfImage + PeHdr.Pe32.OptionalHeader.SectionAlignment;
222 Image->NoPages = EFI_SIZE_TO_PAGES (CodeViewOffset + CodeViewSize);
223
224 //
225 // Compute the amount of memory needed to load the image and
226 // allocate it. Memory starts off as data
227 //
228
229 Image->ImageBasePage = (EFI_PHYSICAL_ADDRESS)FindSpace (Image->NoPages, NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesCode, EFI_MEMORY_WB);
230 if (Image->ImageBasePage == 0) {
231 return EFI_OUT_OF_RESOURCES;
232 }
233
234 if (EFI_ERROR(Status)) {
235 PrintHeader ('J');
236 return Status;
237 }
238
239 // DEBUG((D_LOAD, "LoadPe: new image base %lx\n", Image->ImageBasePage));
240 Image->Info.ImageBase = (VOID *)(UINTN)Image->ImageBasePage;
241 Image->Info.ImageSize = (Image->NoPages << EFI_PAGE_SHIFT) - 1;
242 Image->ImageBase = (UINT8 *)(UINTN)Image->ImageBasePage;
243 Image->ImageEof = Image->ImageBase + Image->Info.ImageSize;
244 Image->ImageAdjust = Image->ImageBase;
245
246 //
247 // Copy the Image header to the base location
248 //
249 Status = EfiLdrPeCoffImageRead (
250 FHand,
251 0,
252 PeHdr.Pe32.OptionalHeader.SizeOfHeaders,
253 Image->ImageBase
254 );
255
256 if (EFI_ERROR(Status)) {
257 PrintHeader ('K');
258 return Status;
259 }
260
261 //
262 // Load each directory of the image into memory...
263 // Save the address of the Debug directory for later
264 //
265 if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
266 NumberOfRvaAndSizes = PeHdr.Pe32.OptionalHeader.NumberOfRvaAndSizes;
267 DataDirectory = PeHdr.Pe32.OptionalHeader.DataDirectory;
268 } else {
269 NumberOfRvaAndSizes = PeHdr.Pe32Plus.OptionalHeader.NumberOfRvaAndSizes;
270 DataDirectory = PeHdr.Pe32Plus.OptionalHeader.DataDirectory;
271 }
272 DebugEntry = NULL;
273 for (Index = 0; Index < NumberOfRvaAndSizes; Index++) {
274 if ((DataDirectory[Index].VirtualAddress != 0) && (DataDirectory[Index].Size != 0)) {
275 Status = EfiLdrPeCoffImageRead (
276 FHand,
277 DataDirectory[Index].VirtualAddress,
278 DataDirectory[Index].Size,
279 Image->ImageBase + DataDirectory[Index].VirtualAddress
280 );
281 if (EFI_ERROR(Status)) {
282 return Status;
283 }
284 if (Index == EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
285 DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (Image->ImageBase + DataDirectory[Index].VirtualAddress);
286 }
287 }
288 }
289
290 //
291 // Load each section of the image
292 //
293
294 // BUGBUG: change this to use the in memory copy
295 if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
296 OptionalHeaderSize = sizeof(EFI_IMAGE_OPTIONAL_HEADER32);
297 PeHeaderSize = sizeof(EFI_IMAGE_NT_HEADERS32);
298 } else {
299 OptionalHeaderSize = sizeof(EFI_IMAGE_OPTIONAL_HEADER64);
300 PeHeaderSize = sizeof(EFI_IMAGE_NT_HEADERS64);
301 }
302 FirstSection = (EFI_IMAGE_SECTION_HEADER *) (
303 Image->ImageBase +
304 DosHdr.e_lfanew +
305 PeHeaderSize +
306 PeHdr.Pe32.FileHeader.SizeOfOptionalHeader -
307 OptionalHeaderSize
308 );
309
310 Section = FirstSection;
311 for (Index=0; Index < PeHdr.Pe32.FileHeader.NumberOfSections; Index += 1) {
312
313 //
314 // Compute sections address
315 //
316
317 Base = EfiLdrPeCoffImageAddress (Image, (UINTN)Section->VirtualAddress);
318 End = EfiLdrPeCoffImageAddress (Image, (UINTN)(Section->VirtualAddress + Section->Misc.VirtualSize));
319
320 if (EFI_ERROR(Status) || !Base || !End) {
321 // DEBUG((D_LOAD|D_ERROR, "LoadPe: Section %d was not loaded\n", Index));
322 PrintHeader ('L');
323 return EFI_LOAD_ERROR;
324 }
325
326 // DEBUG((D_LOAD, "LoadPe: Section %d, loaded at %x\n", Index, Base));
327
328 //
329 // Read the section
330 //
331
332 if (Section->SizeOfRawData) {
333 Status = EfiLdrPeCoffImageRead (FHand, Section->PointerToRawData, Section->SizeOfRawData, Base);
334 if (EFI_ERROR(Status)) {
335 PrintHeader ('M');
336 return Status;
337 }
338 }
339
340 //
341 // If raw size is less then virt size, zero fill the remaining
342 //
343
344 if (Section->SizeOfRawData < Section->Misc.VirtualSize) {
345 ZeroMem (
346 Base + Section->SizeOfRawData,
347 Section->Misc.VirtualSize - Section->SizeOfRawData
348 );
349 }
350
351 //
352 // Next Section
353 //
354
355 Section += 1;
356 }
357
358 //
359 // Copy in CodeView information if it exists
360 //
361 if (CodeViewSize != 0) {
362 Status = EfiLdrPeCoffImageRead (FHand, CodeViewFileOffset, CodeViewSize, Image->ImageBase + CodeViewOffset);
363 DebugEntry->RVA = (UINT32) (CodeViewOffset);
364 }
365
366 //
367 // Apply relocations only if needed
368 //
369 if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
370 ImageBase = (UINT64)PeHdr.Pe32.OptionalHeader.ImageBase;
371 } else {
372 ImageBase = PeHdr.Pe32Plus.OptionalHeader.ImageBase;
373 }
374 if ((UINTN)(Image->ImageBase) != (UINTN) (ImageBase)) {
375 Status = EfiLdrPeCoffLoadPeRelocate (
376 Image,
377 &DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC],
378 (UINTN) Image->ImageBase - (UINTN)ImageBase,
379 NumberOfMemoryMapEntries,
380 EfiMemoryDescriptor
381 );
382
383 if (EFI_ERROR(Status)) {
384 PrintHeader ('N');
385 return Status;
386 }
387 }
388
389 //
390 // Use exported EFI specific interface if present, else use the image's entry point
391 //
392 Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)
393 (EfiLdrPeCoffImageAddress(
394 Image,
395 PeHdr.Pe32.OptionalHeader.AddressOfEntryPoint
396 ));
397
398 return Status;
399 }
400
401 STATIC
402 EFI_STATUS
403 EfiLdrPeCoffLoadPeRelocate (
404 IN EFILDR_LOADED_IMAGE *Image,
405 IN EFI_IMAGE_DATA_DIRECTORY *RelocDir,
406 IN UINTN Adjust,
407 IN UINTN *NumberOfMemoryMapEntries,
408 IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor
409 )
410 {
411 EFI_IMAGE_BASE_RELOCATION *RelocBase;
412 EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd;
413 UINT16 *Reloc;
414 UINT16 *RelocEnd;
415 UINT8 *Fixup;
416 UINT8 *FixupBase;
417 UINT16 *F16;
418 UINT32 *F32;
419 UINT64 *F64;
420 UINT8 *FixupData;
421 UINTN NoFixupPages;
422
423 //
424 // Find the relocation block
425 //
426
427 RelocBase = EfiLdrPeCoffImageAddress (Image, RelocDir->VirtualAddress);
428 RelocBaseEnd = EfiLdrPeCoffImageAddress (Image, RelocDir->VirtualAddress + RelocDir->Size);
429 if (!RelocBase || !RelocBaseEnd) {
430 PrintHeader ('O');
431 return EFI_LOAD_ERROR;
432 }
433
434 NoFixupPages = EFI_SIZE_TO_PAGES(RelocDir->Size / sizeof(UINT16) * sizeof(UINTN));
435 Image->FixupData = (UINT8*) FindSpace (NoFixupPages, NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB);
436 if (Image->FixupData == 0) {
437 return EFI_OUT_OF_RESOURCES;
438 }
439
440 //
441 // Run the whole relocation block
442 //
443
444 FixupData = Image->FixupData;
445 while (RelocBase < RelocBaseEnd) {
446
447 Reloc = (UINT16 *) ((UINT8 *) RelocBase + sizeof(EFI_IMAGE_BASE_RELOCATION));
448 RelocEnd = (UINT16 *) ((UINT8 *) RelocBase + RelocBase->SizeOfBlock);
449 FixupBase = EfiLdrPeCoffImageAddress (Image, RelocBase->VirtualAddress);
450 if ((UINT8 *) RelocEnd < Image->ImageBase || (UINT8 *) RelocEnd > Image->ImageEof) {
451 PrintHeader ('P');
452 return EFI_LOAD_ERROR;
453 }
454
455 //
456 // Run this relocation record
457 //
458
459 while (Reloc < RelocEnd) {
460
461 Fixup = FixupBase + (*Reloc & 0xFFF);
462 switch ((*Reloc) >> 12) {
463
464 case EFI_IMAGE_REL_BASED_ABSOLUTE:
465 break;
466
467 case EFI_IMAGE_REL_BASED_HIGH:
468 F16 = (UINT16 *) Fixup;
469 *F16 = (UINT16) (*F16 + (UINT16)(((UINT32)Adjust) >> 16));
470 if (FixupData != NULL) {
471 *(UINT16 *) FixupData = *F16;
472 FixupData = FixupData + sizeof(UINT16);
473 }
474 break;
475
476 case EFI_IMAGE_REL_BASED_LOW:
477 F16 = (UINT16 *) Fixup;
478 *F16 = *F16 + (UINT16) Adjust;
479 if (FixupData != NULL) {
480 *(UINT16 *) FixupData = *F16;
481 FixupData = FixupData + sizeof(UINT16);
482 }
483 break;
484
485 case EFI_IMAGE_REL_BASED_HIGHLOW:
486 F32 = (UINT32 *) Fixup;
487 *F32 = *F32 + (UINT32) Adjust;
488 if (FixupData != NULL) {
489 FixupData = ALIGN_POINTER(FixupData, sizeof(UINT32));
490 *(UINT32 *) FixupData = *F32;
491 FixupData = FixupData + sizeof(UINT32);
492 }
493 break;
494
495 case EFI_IMAGE_REL_BASED_DIR64:
496 F64 = (UINT64 *) Fixup;
497 *F64 = *F64 + (UINT64) Adjust;
498 if (FixupData != NULL) {
499 FixupData = ALIGN_POINTER(FixupData, sizeof(UINT64));
500 *(UINT64 *) FixupData = *F64;
501 FixupData = FixupData + sizeof(UINT64);
502 }
503 break;
504
505 case EFI_IMAGE_REL_BASED_HIGHADJ:
506 CpuDeadLoop(); // BUGBUG: not done
507 break;
508
509 default:
510 // DEBUG((D_LOAD|D_ERROR, "PeRelocate: unknown fixed type\n"));
511 PrintHeader ('Q');
512 CpuDeadLoop();
513 return EFI_LOAD_ERROR;
514 }
515
516 // Next reloc record
517 Reloc += 1;
518 }
519
520 // next reloc block
521 RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd;
522 }
523
524 //
525 // Add Fixup data to whole Image (assume Fixup data just below the image), so that there is no hole in the descriptor.
526 // Because only NoPages or ImageBasePage will be used in EfiLoader(), we update these 2 fields.
527 //
528 Image->NoPages += NoFixupPages;
529 Image->ImageBasePage -= (NoFixupPages << EFI_PAGE_SHIFT);
530
531 return EFI_SUCCESS;
532 }
533
534 STATIC
535 EFI_STATUS
536 EfiLdrPeCoffImageRead (
537 IN VOID *FHand,
538 IN UINTN Offset,
539 IN OUT UINTN ReadSize,
540 OUT VOID *Buffer
541 )
542 {
543 CopyMem (Buffer, (VOID *)((UINTN)FHand + Offset), ReadSize);
544
545 return EFI_SUCCESS;
546 }
547
548 STATIC
549 VOID *
550 EfiLdrPeCoffImageAddress (
551 IN EFILDR_LOADED_IMAGE *Image,
552 IN UINTN Address
553 )
554 {
555 UINT8 *FixedAddress;
556
557 FixedAddress = Image->ImageAdjust + Address;
558
559 if ((FixedAddress < Image->ImageBase) || (FixedAddress > Image->ImageEof)) {
560 // DEBUG((D_LOAD|D_ERROR, "PeCoffImageAddress: pointer is outside of image\n"));
561 FixedAddress = NULL;
562 }
563
564 // DEBUG((
565 // D_LOAD,
566 // "PeCoffImageAddress: ImageBase %x, ImageEof %x, Address %x, FixedAddress %x\n",
567 // Image->ImageBase,
568 // Image->ImageEof,
569 // Address,
570 // FixedAddress
571 // ));
572 return FixedAddress;
573 }
574
575
576 EFI_STATUS
577 EfiLdrPeCoffSetImageType (
578 IN OUT EFILDR_LOADED_IMAGE *Image,
579 IN UINTN ImageType
580 )
581 {
582 EFI_MEMORY_TYPE CodeType;
583 EFI_MEMORY_TYPE DataType;
584
585 switch (ImageType) {
586 case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
587 CodeType = EfiLoaderCode;
588 DataType = EfiLoaderData;
589 break;
590
591 case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
592 CodeType = EfiBootServicesCode;
593 DataType = EfiBootServicesData;
594 break;
595
596 case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
597 CodeType = EfiRuntimeServicesCode;
598 DataType = EfiRuntimeServicesData;
599 break;
600
601 default:
602 return EFI_INVALID_PARAMETER;
603 }
604
605 Image->Type = ImageType;
606 Image->Info.ImageCodeType = CodeType;
607 Image->Info.ImageDataType = DataType;
608
609 return EFI_SUCCESS;
610 }
611
612 EFI_STATUS
613 EfiLdrPeCoffCheckImageMachineType (
614 IN UINT16 MachineType
615 )
616 {
617 EFI_STATUS Status;
618
619 Status = EFI_UNSUPPORTED;
620
621 #if EFI32
622 if (MachineType == EFI_IMAGE_MACHINE_IA32) {
623 Status = EFI_SUCCESS;
624 }
625 #endif
626
627 #if EFIX64
628 if (MachineType == EFI_IMAGE_MACHINE_X64) {
629 Status = EFI_SUCCESS;
630 }
631 #endif
632
633 #if EFI64
634 if (MachineType == EFI_IMAGE_MACHINE_IA64) {
635 Status = EFI_SUCCESS;
636 }
637 #endif
638
639 return Status;
640 }
641