3 Copyright (c) 2004, 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
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.
18 Fixes Intel Itanium(TM) specific relocation types
25 #include "TianoCommon.h"
28 #define EXT_IMM64(Value, Address, Size, InstPos, ValPos) \
29 Value |= (((UINT64)((*(Address) >> InstPos) & (((UINT64)1 << Size) - 1))) << ValPos)
31 #define INS_IMM64(Value, Address, Size, InstPos, ValPos) \
32 *(UINT32*)Address = (*(UINT32*)Address & ~(((1 << Size) - 1) << InstPos)) | \
33 ((UINT32)((((UINT64)Value >> ValPos) & (((UINT64)1 << Size) - 1))) << InstPos)
35 #define IMM64_IMM7B_INST_WORD_X 3
36 #define IMM64_IMM7B_SIZE_X 7
37 #define IMM64_IMM7B_INST_WORD_POS_X 4
38 #define IMM64_IMM7B_VAL_POS_X 0
40 #define IMM64_IMM9D_INST_WORD_X 3
41 #define IMM64_IMM9D_SIZE_X 9
42 #define IMM64_IMM9D_INST_WORD_POS_X 18
43 #define IMM64_IMM9D_VAL_POS_X 7
45 #define IMM64_IMM5C_INST_WORD_X 3
46 #define IMM64_IMM5C_SIZE_X 5
47 #define IMM64_IMM5C_INST_WORD_POS_X 13
48 #define IMM64_IMM5C_VAL_POS_X 16
50 #define IMM64_IC_INST_WORD_X 3
51 #define IMM64_IC_SIZE_X 1
52 #define IMM64_IC_INST_WORD_POS_X 12
53 #define IMM64_IC_VAL_POS_X 21
55 #define IMM64_IMM41a_INST_WORD_X 1
56 #define IMM64_IMM41a_SIZE_X 10
57 #define IMM64_IMM41a_INST_WORD_POS_X 14
58 #define IMM64_IMM41a_VAL_POS_X 22
60 #define IMM64_IMM41b_INST_WORD_X 1
61 #define IMM64_IMM41b_SIZE_X 8
62 #define IMM64_IMM41b_INST_WORD_POS_X 24
63 #define IMM64_IMM41b_VAL_POS_X 32
65 #define IMM64_IMM41c_INST_WORD_X 2
66 #define IMM64_IMM41c_SIZE_X 23
67 #define IMM64_IMM41c_INST_WORD_POS_X 0
68 #define IMM64_IMM41c_VAL_POS_X 40
70 #define IMM64_SIGN_INST_WORD_X 3
71 #define IMM64_SIGN_SIZE_X 1
72 #define IMM64_SIGN_INST_WORD_POS_X 27
73 #define IMM64_SIGN_VAL_POS_X 63
76 PeCoffLoaderRelocateImageEx (
79 IN OUT CHAR8
**FixupData
,
86 Performs an Itanium-based specific relocation fixup
90 Reloc - Pointer to the relocation record
92 Fixup - Pointer to the address to fix up
94 FixupData - Pointer to a buffer to log the fixups
96 Adjust - The offset to adjust the fixup
107 switch ((*Reloc
) >> 12) {
109 case EFI_IMAGE_REL_BASED_DIR64
:
110 F64
= (UINT64
*) Fixup
;
111 *F64
= *F64
+ (UINT64
) Adjust
;
112 if (*FixupData
!= NULL
) {
113 *FixupData
= ALIGN_POINTER(*FixupData
, sizeof(UINT64
));
114 *(UINT64
*)(*FixupData
) = *F64
;
115 *FixupData
= *FixupData
+ sizeof(UINT64
);
119 case EFI_IMAGE_REL_BASED_IA64_IMM64
:
122 // Align it to bundle address before fixing up the
123 // 64-bit immediate value of the movl instruction.
126 Fixup
= (CHAR8
*)((UINTN
) Fixup
& (UINTN
) ~(15));
127 FixupVal
= (UINT64
)0;
130 // Extract the lower 32 bits of IMM64 from bundle
133 (UINT32
*)Fixup
+ IMM64_IMM7B_INST_WORD_X
,
135 IMM64_IMM7B_INST_WORD_POS_X
,
136 IMM64_IMM7B_VAL_POS_X
140 (UINT32
*)Fixup
+ IMM64_IMM9D_INST_WORD_X
,
142 IMM64_IMM9D_INST_WORD_POS_X
,
143 IMM64_IMM9D_VAL_POS_X
147 (UINT32
*)Fixup
+ IMM64_IMM5C_INST_WORD_X
,
149 IMM64_IMM5C_INST_WORD_POS_X
,
150 IMM64_IMM5C_VAL_POS_X
154 (UINT32
*)Fixup
+ IMM64_IC_INST_WORD_X
,
156 IMM64_IC_INST_WORD_POS_X
,
161 (UINT32
*)Fixup
+ IMM64_IMM41a_INST_WORD_X
,
163 IMM64_IMM41a_INST_WORD_POS_X
,
164 IMM64_IMM41a_VAL_POS_X
168 // Update 64-bit address
173 // Insert IMM64 into bundle
176 ((UINT32
*)Fixup
+ IMM64_IMM7B_INST_WORD_X
),
178 IMM64_IMM7B_INST_WORD_POS_X
,
179 IMM64_IMM7B_VAL_POS_X
183 ((UINT32
*)Fixup
+ IMM64_IMM9D_INST_WORD_X
),
185 IMM64_IMM9D_INST_WORD_POS_X
,
186 IMM64_IMM9D_VAL_POS_X
190 ((UINT32
*)Fixup
+ IMM64_IMM5C_INST_WORD_X
),
192 IMM64_IMM5C_INST_WORD_POS_X
,
193 IMM64_IMM5C_VAL_POS_X
197 ((UINT32
*)Fixup
+ IMM64_IC_INST_WORD_X
),
199 IMM64_IC_INST_WORD_POS_X
,
204 ((UINT32
*)Fixup
+ IMM64_IMM41a_INST_WORD_X
),
206 IMM64_IMM41a_INST_WORD_POS_X
,
207 IMM64_IMM41a_VAL_POS_X
211 ((UINT32
*)Fixup
+ IMM64_IMM41b_INST_WORD_X
),
213 IMM64_IMM41b_INST_WORD_POS_X
,
214 IMM64_IMM41b_VAL_POS_X
218 ((UINT32
*)Fixup
+ IMM64_IMM41c_INST_WORD_X
),
220 IMM64_IMM41c_INST_WORD_POS_X
,
221 IMM64_IMM41c_VAL_POS_X
225 ((UINT32
*)Fixup
+ IMM64_SIGN_INST_WORD_X
),
227 IMM64_SIGN_INST_WORD_POS_X
,
231 F64
= (UINT64
*) Fixup
;
232 if (*FixupData
!= NULL
) {
233 *FixupData
= ALIGN_POINTER(*FixupData
, sizeof(UINT64
));
234 *(UINT64
*)(*FixupData
) = *F64
;
235 *FixupData
= *FixupData
+ sizeof(UINT64
);
240 return EFI_UNSUPPORTED
;