]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/BasePeCoffLib/AArch64/PeCoffLoaderEx.c
ArmPkg: Added Aarch64 support
[mirror_edk2.git] / ArmPkg / Library / BasePeCoffLib / AArch64 / PeCoffLoaderEx.c
1 /** @file
2 Specific relocation fixups for ARM architecture.
3
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
6 Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
7
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php.
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include "BasePeCoffLibInternals.h"
19 #include <Library/BaseLib.h>
20
21 //
22 // Note: Currently only large memory model is supported by UEFI relocation code.
23 //
24
25 /**
26 Performs an AARCH64-based specific relocation fixup and is a no-op on other
27 instruction sets.
28
29 @param Reloc The pointer to the relocation record.
30 @param Fixup The pointer to the address to fix up.
31 @param FixupData The pointer to a buffer to log the fixups.
32 @param Adjust The offset to adjust the fixup.
33
34 @return Status code.
35
36 **/
37 RETURN_STATUS
38 PeCoffLoaderRelocateImageEx (
39 IN UINT16 **Reloc,
40 IN OUT CHAR8 *Fixup,
41 IN OUT CHAR8 **FixupData,
42 IN UINT64 Adjust
43 )
44 {
45 UINT64 *F64;
46
47 switch ((**Reloc) >> 12) {
48
49 case EFI_IMAGE_REL_BASED_DIR64:
50 F64 = (UINT64 *) Fixup;
51 *F64 = *F64 + (UINT64) Adjust;
52 if (*FixupData != NULL) {
53 *FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));
54 *(UINT64 *)(*FixupData) = *F64;
55 *FixupData = *FixupData + sizeof(UINT64);
56 }
57 break;
58
59 default:
60 return RETURN_UNSUPPORTED;
61 }
62
63 return RETURN_SUCCESS;
64 }
65
66 /**
67 Returns TRUE if the machine type of PE/COFF image is supported. Supported
68 does not mean the image can be executed it means the PE/COFF loader supports
69 loading and relocating of the image type. It's up to the caller to support
70 the entry point.
71
72 @param Machine Machine type from the PE Header.
73
74 @return TRUE if this PE/COFF loader can load the image
75
76 **/
77 BOOLEAN
78 PeCoffLoaderImageFormatSupported (
79 IN UINT16 Machine
80 )
81 {
82 if ((Machine == IMAGE_FILE_MACHINE_AARCH64) || (Machine == IMAGE_FILE_MACHINE_EBC)) {
83 return TRUE;
84 }
85
86 return FALSE;
87 }
88
89 /**
90 Performs an ARM-based specific re-relocation fixup and is a no-op on other
91 instruction sets. This is used to re-relocated the image into the EFI virtual
92 space for runtime calls.
93
94 @param Reloc The pointer to the relocation record.
95 @param Fixup The pointer to the address to fix up.
96 @param FixupData The pointer to a buffer to log the fixups.
97 @param Adjust The offset to adjust the fixup.
98
99 @return Status code.
100
101 **/
102 RETURN_STATUS
103 PeHotRelocateImageEx (
104 IN UINT16 **Reloc,
105 IN OUT CHAR8 *Fixup,
106 IN OUT CHAR8 **FixupData,
107 IN UINT64 Adjust
108 )
109 {
110 UINT64 *Fixup64;
111
112 switch ((**Reloc) >> 12) {
113 case EFI_IMAGE_REL_BASED_DIR64:
114 Fixup64 = (UINT64 *) Fixup;
115 *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT64));
116 if (*(UINT64 *) (*FixupData) == *Fixup64) {
117 *Fixup64 = *Fixup64 + (UINT64) Adjust;
118 }
119
120 *FixupData = *FixupData + sizeof (UINT64);
121 break;
122
123 default:
124 DEBUG ((EFI_D_ERROR, "PeHotRelocateEx:unknown fixed type\n"));
125 return RETURN_UNSUPPORTED;
126 }
127
128 return RETURN_SUCCESS;
129 }