TianoCore EDK2 master
Loading...
Searching...
No Matches
PeCoffLoaderEx.c
Go to the documentation of this file.
1
8#include <Library/BaseLib.h>
9
26RETURN_STATUS
28 IN UINT16 *Reloc,
29 IN OUT CHAR8 *Fixup,
30 IN OUT CHAR8 **FixupData,
31 IN UINT64 Adjust
32 )
33{
34 UINT32 Value;
35 UINT32 Value2;
36 UINT32 *RiscVHi20Fixup;
37
38 switch ((*Reloc) >> 12) {
40 *(UINT64 *)(*FixupData) = (UINT64)(UINTN)Fixup;
41 break;
42
43 case EFI_IMAGE_REL_BASED_RISCV_LOW12I:
44 RiscVHi20Fixup = (UINT32 *)(*(UINT64 *)(*FixupData));
45 if (RiscVHi20Fixup != NULL) {
46 Value = (UINT32)(RV_X (*RiscVHi20Fixup, 12, 20) << 12);
47 Value2 = (UINT32)(RV_X (*(UINT32 *)Fixup, 20, 12));
48 if (Value2 & (RISCV_IMM_REACH/2)) {
49 Value2 |= ~(RISCV_IMM_REACH-1);
50 }
51
52 Value += Value2;
53 Value += (UINT32)Adjust;
54 Value2 = RISCV_CONST_HIGH_PART (Value);
55 *(UINT32 *)RiscVHi20Fixup = (RV_X (Value2, 12, 20) << 12) | \
56 (RV_X (*(UINT32 *)RiscVHi20Fixup, 0, 12));
57 *(UINT32 *)Fixup = (RV_X (Value, 0, 12) << 20) | \
58 (RV_X (*(UINT32 *)Fixup, 0, 20));
59 }
60
61 break;
62
63 case EFI_IMAGE_REL_BASED_RISCV_LOW12S:
64 RiscVHi20Fixup = (UINT32 *)(*(UINT64 *)(*FixupData));
65 if (RiscVHi20Fixup != NULL) {
66 Value = (UINT32)(RV_X (*RiscVHi20Fixup, 12, 20) << 12);
67 Value2 = (UINT32)(RV_X (*(UINT32 *)Fixup, 7, 5) | (RV_X (*(UINT32 *)Fixup, 25, 7) << 5));
68 if (Value2 & (RISCV_IMM_REACH/2)) {
69 Value2 |= ~(RISCV_IMM_REACH-1);
70 }
71
72 Value += Value2;
73 Value += (UINT32)Adjust;
74 Value2 = RISCV_CONST_HIGH_PART (Value);
75 *(UINT32 *)RiscVHi20Fixup = (RV_X (Value2, 12, 20) << 12) | \
76 (RV_X (*(UINT32 *)RiscVHi20Fixup, 0, 12));
77 Value2 = *(UINT32 *)Fixup & 0x01fff07f;
78 Value &= RISCV_IMM_REACH - 1;
79 *(UINT32 *)Fixup = Value2 | (UINT32)(((RV_X (Value, 0, 5) << 7) | (RV_X (Value, 5, 7) << 25)));
80 }
81
82 break;
83
84 default:
85 return RETURN_UNSUPPORTED;
86 }
87
88 return RETURN_SUCCESS;
89}
90
102BOOLEAN
104 IN UINT16 Machine
105 )
106{
107 /*
108 * ARM64 and X64 may allow such foreign images to be used when
109 * a driver implementing EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL is
110 * present.
111 */
112 if ((Machine == IMAGE_FILE_MACHINE_RISCV64) ||
113 (Machine == IMAGE_FILE_MACHINE_ARM64) ||
114 (Machine == IMAGE_FILE_MACHINE_X64))
115 {
116 return TRUE;
117 }
118
119 return FALSE;
120}
121
135RETURN_STATUS
137 IN UINT16 *Reloc,
138 IN OUT CHAR8 *Fixup,
139 IN OUT CHAR8 **FixupData,
140 IN UINT64 Adjust
141 )
142{
143 return RETURN_UNSUPPORTED;
144}
UINT64 UINTN
RETURN_STATUS PeHotRelocateImageEx(IN UINT16 *Reloc, IN OUT CHAR8 *Fixup, IN OUT CHAR8 **FixupData, IN UINT64 Adjust)
RETURN_STATUS PeCoffLoaderRelocateImageEx(IN UINT16 *Reloc, IN OUT CHAR8 *Fixup, IN OUT CHAR8 **FixupData, IN UINT64 Adjust)
BOOLEAN PeCoffLoaderImageFormatSupported(IN UINT16 Machine)
#define NULL
Definition: Base.h:319
#define RETURN_UNSUPPORTED
Definition: Base.h:1081
#define RETURN_SUCCESS
Definition: Base.h:1066
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define EFI_IMAGE_REL_BASED_RISCV_HI20
Definition: PeImage.h:521