TianoCore EDK2 master
Loading...
Searching...
No Matches
PeCoffLoaderEx.c
Go to the documentation of this file.
1
10#include <Library/BaseLib.h>
11
24RETURN_STATUS
26 IN UINT16 *Reloc,
27 IN OUT CHAR8 *Fixup,
28 IN OUT CHAR8 **FixupData,
29 IN UINT64 Adjust
30 )
31{
32 UINT8 RelocType;
33 UINT64 Value;
34 UINT64 Tmp1;
35 UINT64 Tmp2;
36
37 RelocType = (*Reloc) >> 12;
38 Value = 0;
39 Tmp1 = 0;
40 Tmp2 = 0;
41
42 switch (RelocType) {
43 case EFI_IMAGE_REL_BASED_LOONGARCH64_MARK_LA:
44 // The next four instructions are used to load a 64 bit address, relocate all of them
45 Value = (*(UINT32 *)Fixup & 0x1ffffe0) << 7 | // lu12i.w 20bits from bit5
46 (*((UINT32 *)Fixup + 1) & 0x3ffc00) >> 10; // ori 12bits from bit10
47 Tmp1 = *((UINT32 *)Fixup + 2) & 0x1ffffe0; // lu32i.d 20bits from bit5
48 Tmp2 = *((UINT32 *)Fixup + 3) & 0x3ffc00; // lu52i.d 12bits from bit10
49 Value = Value | (Tmp1 << 27) | (Tmp2 << 42);
50 Value += Adjust;
51
52 *(UINT32 *)Fixup = (*(UINT32 *)Fixup & ~0x1ffffe0) | (((Value >> 12) & 0xfffff) << 5);
53 if (*FixupData != NULL) {
54 *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT32));
55 *(UINT32 *)(*FixupData) = *(UINT32 *)Fixup;
56 *FixupData = *FixupData + sizeof (UINT32);
57 }
58
59 Fixup += sizeof (UINT32);
60 *(UINT32 *)Fixup = (*(UINT32 *)Fixup & ~0x3ffc00) | ((Value & 0xfff) << 10);
61 if (*FixupData != NULL) {
62 *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT32));
63 *(UINT32 *)(*FixupData) = *(UINT32 *)Fixup;
64 *FixupData = *FixupData + sizeof (UINT32);
65 }
66
67 Fixup += sizeof (UINT32);
68 *(UINT32 *)Fixup = (*(UINT32 *)Fixup & ~0x1ffffe0) | (((Value >> 32) & 0xfffff) << 5);
69 if (*FixupData != NULL) {
70 *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT32));
71 *(UINT32 *)(*FixupData) = *(UINT32 *)Fixup;
72 *FixupData = *FixupData + sizeof (UINT32);
73 }
74
75 Fixup += sizeof (UINT32);
76 *(UINT32 *)Fixup = (*(UINT32 *)Fixup & ~0x3ffc00) | (((Value >> 52) & 0xfff) << 10);
77 if (*FixupData != NULL) {
78 *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT32));
79 *(UINT32 *)(*FixupData) = *(UINT32 *)Fixup;
80 *FixupData = *FixupData + sizeof (UINT32);
81 }
82
83 break;
84 default:
85 return RETURN_UNSUPPORTED;
86 }
87
88 return RETURN_SUCCESS;
89}
90
102BOOLEAN
104 IN UINT16 Machine
105 )
106{
107 if (Machine == IMAGE_FILE_MACHINE_LOONGARCH64) {
108 return TRUE;
109 }
110
111 return FALSE;
112}
113
127RETURN_STATUS
129 IN UINT16 *Reloc,
130 IN OUT CHAR8 *Fixup,
131 IN OUT CHAR8 **FixupData,
132 IN UINT64 Adjust
133 )
134{
135 // To check
136 return PeCoffLoaderRelocateImageEx (Reloc, Fixup, FixupData, Adjust);
137}
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 ALIGN_POINTER(Pointer, Alignment)
Definition: Base.h:963
#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