2 Fixes Intel Itanium(TM) specific relocation types.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 Module Name: PeCoffLoaderEx.c
21 #define EXT_IMM64(Value, Address, Size, InstPos, ValPos) \
22 Value |= (((UINT64)((*(Address) >> InstPos) & (((UINT64)1 << Size) - 1))) << ValPos)
24 #define INS_IMM64(Value, Address, Size, InstPos, ValPos) \
25 *(UINT32*)Address = (*(UINT32*)Address & ~(((1 << Size) - 1) << InstPos)) | \
26 ((UINT32)((((UINT64)Value >> ValPos) & (((UINT64)1 << Size) - 1))) << InstPos)
28 #define IMM64_IMM7B_INST_WORD_X 3
29 #define IMM64_IMM7B_SIZE_X 7
30 #define IMM64_IMM7B_INST_WORD_POS_X 4
31 #define IMM64_IMM7B_VAL_POS_X 0
33 #define IMM64_IMM9D_INST_WORD_X 3
34 #define IMM64_IMM9D_SIZE_X 9
35 #define IMM64_IMM9D_INST_WORD_POS_X 18
36 #define IMM64_IMM9D_VAL_POS_X 7
38 #define IMM64_IMM5C_INST_WORD_X 3
39 #define IMM64_IMM5C_SIZE_X 5
40 #define IMM64_IMM5C_INST_WORD_POS_X 13
41 #define IMM64_IMM5C_VAL_POS_X 16
43 #define IMM64_IC_INST_WORD_X 3
44 #define IMM64_IC_SIZE_X 1
45 #define IMM64_IC_INST_WORD_POS_X 12
46 #define IMM64_IC_VAL_POS_X 21
48 #define IMM64_IMM41a_INST_WORD_X 1
49 #define IMM64_IMM41a_SIZE_X 10
50 #define IMM64_IMM41a_INST_WORD_POS_X 14
51 #define IMM64_IMM41a_VAL_POS_X 22
53 #define IMM64_IMM41b_INST_WORD_X 1
54 #define IMM64_IMM41b_SIZE_X 8
55 #define IMM64_IMM41b_INST_WORD_POS_X 24
56 #define IMM64_IMM41b_VAL_POS_X 32
58 #define IMM64_IMM41c_INST_WORD_X 2
59 #define IMM64_IMM41c_SIZE_X 23
60 #define IMM64_IMM41c_INST_WORD_POS_X 0
61 #define IMM64_IMM41c_VAL_POS_X 40
63 #define IMM64_SIGN_INST_WORD_X 3
64 #define IMM64_SIGN_SIZE_X 1
65 #define IMM64_SIGN_INST_WORD_POS_X 27
66 #define IMM64_SIGN_VAL_POS_X 63
69 Performs an Itanium-based specific relocation fixup.
71 @param Reloc Pointer to the relocation record.
72 @param Fixup Pointer to the address to fix up.
73 @param FixupData Pointer to a buffer to log the fixups.
74 @param Adjust The offset to adjust the fixup.
80 PeCoffLoaderRelocateImageEx (
83 IN OUT CHAR8
**FixupData
,
90 switch ((*Reloc
) >> 12) {
92 case EFI_IMAGE_REL_BASED_DIR64
:
93 F64
= (UINT64
*) Fixup
;
94 *F64
= *F64
+ (UINT64
) Adjust
;
95 if (*FixupData
!= NULL
) {
96 *FixupData
= ALIGN_POINTER(*FixupData
, sizeof(UINT64
));
97 *(UINT64
*)(*FixupData
) = *F64
;
98 *FixupData
= *FixupData
+ sizeof(UINT64
);
102 case EFI_IMAGE_REL_BASED_IA64_IMM64
:
105 // Align it to bundle address before fixing up the
106 // 64-bit immediate value of the movl instruction.
109 Fixup
= (CHAR8
*)((UINTN
) Fixup
& (UINTN
) ~(15));
110 FixupVal
= (UINT64
)0;
113 // Extract the lower 32 bits of IMM64 from bundle
116 (UINT32
*)Fixup
+ IMM64_IMM7B_INST_WORD_X
,
118 IMM64_IMM7B_INST_WORD_POS_X
,
119 IMM64_IMM7B_VAL_POS_X
123 (UINT32
*)Fixup
+ IMM64_IMM9D_INST_WORD_X
,
125 IMM64_IMM9D_INST_WORD_POS_X
,
126 IMM64_IMM9D_VAL_POS_X
130 (UINT32
*)Fixup
+ IMM64_IMM5C_INST_WORD_X
,
132 IMM64_IMM5C_INST_WORD_POS_X
,
133 IMM64_IMM5C_VAL_POS_X
137 (UINT32
*)Fixup
+ IMM64_IC_INST_WORD_X
,
139 IMM64_IC_INST_WORD_POS_X
,
144 (UINT32
*)Fixup
+ IMM64_IMM41a_INST_WORD_X
,
146 IMM64_IMM41a_INST_WORD_POS_X
,
147 IMM64_IMM41a_VAL_POS_X
151 // Update 64-bit address
156 // Insert IMM64 into bundle
159 ((UINT32
*)Fixup
+ IMM64_IMM7B_INST_WORD_X
),
161 IMM64_IMM7B_INST_WORD_POS_X
,
162 IMM64_IMM7B_VAL_POS_X
166 ((UINT32
*)Fixup
+ IMM64_IMM9D_INST_WORD_X
),
168 IMM64_IMM9D_INST_WORD_POS_X
,
169 IMM64_IMM9D_VAL_POS_X
173 ((UINT32
*)Fixup
+ IMM64_IMM5C_INST_WORD_X
),
175 IMM64_IMM5C_INST_WORD_POS_X
,
176 IMM64_IMM5C_VAL_POS_X
180 ((UINT32
*)Fixup
+ IMM64_IC_INST_WORD_X
),
182 IMM64_IC_INST_WORD_POS_X
,
187 ((UINT32
*)Fixup
+ IMM64_IMM41a_INST_WORD_X
),
189 IMM64_IMM41a_INST_WORD_POS_X
,
190 IMM64_IMM41a_VAL_POS_X
194 ((UINT32
*)Fixup
+ IMM64_IMM41b_INST_WORD_X
),
196 IMM64_IMM41b_INST_WORD_POS_X
,
197 IMM64_IMM41b_VAL_POS_X
201 ((UINT32
*)Fixup
+ IMM64_IMM41c_INST_WORD_X
),
203 IMM64_IMM41c_INST_WORD_POS_X
,
204 IMM64_IMM41c_VAL_POS_X
208 ((UINT32
*)Fixup
+ IMM64_SIGN_INST_WORD_X
),
210 IMM64_SIGN_INST_WORD_POS_X
,
214 F64
= (UINT64
*) Fixup
;
215 if (*FixupData
!= NULL
) {
216 *FixupData
= ALIGN_POINTER(*FixupData
, sizeof(UINT64
));
217 *(UINT64
*)(*FixupData
) = *F64
;
218 *FixupData
= *FixupData
+ sizeof(UINT64
);
223 return RETURN_UNSUPPORTED
;
226 return RETURN_SUCCESS
;