From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.5029.1663917511783335505 for ; Fri, 23 Sep 2022 00:18:32 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: loongson.cn, ip: 114.242.206.163, mailfrom: lichao@loongson.cn) Received: from lichao-PC (unknown [10.40.24.149]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxkODEXS1jPYsgAA--.56809S2; Fri, 23 Sep 2022 15:18:28 +0800 (CST) Date: Fri, 23 Sep 2022 15:18:28 +0800 From: "Chao Li" To: Michael D Kinney , Liming Gao , Zhiguang Liu , Baoqi Zhang Cc: "=?utf-8?Q?devel=40edk2.groups.io?=" Message-ID: In-Reply-To: <20220914094131.3697140-1-lichao@loongson.cn> References: <20220914094131.3697140-1-lichao@loongson.cn> Subject: Re: [PATCH v2 26/34] MdePkg/BasePeCoff: Add LoongArch PE/Coff related code. X-Mailer: Mailspring MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxkODEXS1jPYsgAA--.56809S2 X-Coremail-Antispam: 1UD129KBjvJXoWxKrW8uF1DArWUXF45tFW3trb_yoWfXryfpa 9rKan5WwnrJw4fArW5K3W3GrsYgFsrWasxGFWq9r48ZFsxZanY9w4UtF15trWUZryDA348 uFsI9r47ua1kJr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBlb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40Eb7x2 x7xS6r1j6r4UMc02F40EFcxC0VAKzVAqx4xG6I80ewAqx4xG64kEw2xG04xIwI0_Gr0_Xr 1lYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwCjr7xvwVCIw2I0I7xG6c02F41lc2xSY4AK6svPMx AIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_JrI_ JrWlx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwI xGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWx JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcV C2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU5ZL07UUUUU== X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQASCGMsUF0TtQAcsj Content-Type: multipart/alternative; boundary="632d5dc4_3a4fcd4a_dbe1" --632d5dc4_3a4fcd4a_dbe1 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi Mike, Liming and Zhiguang, This patch has not been reviewed, would you please review it=3F Thanks, Chao -------- On 9=E6=9C=88 14 2022, at 5:41 =E4=B8=8B=E5=8D=88, Chao Li wrote: > RE=46: https://bugzilla.tianocore.org/show=5Fbug.cgi=3Fid=3D4053 > > Add LoongArch image relocation. > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > > Signed-off-by: Chao Li > Co-authored-by: Baoqi Zhang > --- > MdePkg/Library/BasePeCoffLib/BasePeCoff.c =7C 3 +- > .../Library/BasePeCoffLib/BasePeCoffLib.inf =7C 5 + > .../Library/BasePeCoffLib/BasePeCoffLib.uni =7C 2 + > .../BasePeCoffLib/LoongArch/PeCoffLoaderEx.c =7C 137 ++++++++++++++++++= > 4 files changed, 146 insertions(+), 1 deletion(-) > create mode 100644 MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoaderE= x.c > > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library= /BasePeCoffLib/BasePeCoff.c > index 6d8d9faeb8..97a8aaf8c7 100644 > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c > =40=40 -1,6 +1,6 =40=40 > /** =40file > > Base PE/CO=46=46 loader supports loading any PE32/PE32+ or TE image, bu= t > - only supports relocating IA32, x64, IP=46, ARM, RISC-V and EBC images= . > + only supports relocating IA32, x64, IP=46, ARM, RISC-V, LoongArch and= EBC images. > > > Caution: This file requires additional review when modified. > This library will have external input - PE/CO=46=46 image. > =40=40 -18,6 +18,7 =40=40 > Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> > Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
= > Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP.= All rights reserved.
> + Portions Copyright (c) 2022, Loongson Technology Corporation Limited.= All rights reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent > > > **/ > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf b/MdePkg/Li= brary/BasePeCoffLib/BasePeCoffLib.inf > index 110b6d5a09..3b8b8eb191 100644 > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf > =40=40 -4,6 +4,7 =40=40 > =23 The IA32 version library support loading IA32, X64 and EBC PE/CO=46= =46 images. > > =23 The X64 version library support loading IA32, X64 and EBC PE/CO=46=46= images. > =23 The RISC-V version library support loading RISC-V images. > +=23 The LoongArch version library support loading LoongArch images. > =23 > =23 Caution: This module requires additional review when modified. > =23 This library will have external input - PE/CO=46=46 image. > =40=40 -13,6 +14,7 =40=40 > =23 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<= BR> > > =23 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.=
> =23 Portions Copyright (c) 2020, Hewlett Packard Enterprise Development= LP. All rights reserved.
> +=23 Portions Copyright (c) 2022, Loongson Technology Corporation Limit= ed. All rights reserved.
> =23 > =23 SPDX-License-Identifier: BSD-2-Clause-Patent > =23 > =40=40 -46,6 +48,9 =40=40 > =5BSources.RISCV64=5D > > RiscV/PeCoffLoaderEx.c > > > +=5BSources.LOONGARCH64=5D > + LoongArch/PeCoffLoaderEx.c > + > =5BPackages=5D > MdePkg/MdePkg.dec > > > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni b/MdePkg/Li= brary/BasePeCoffLib/BasePeCoffLib.uni > index 55417029f2..1f731344e1 100644 > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni > =40=40 -5,6 +5,7 =40=40 > // The IA32 version library support loading IA32, X64 and EBC PE/CO=46=46= images. > > // The X64 version library support loading IA32, X64 and EBC PE/CO=46=46= images. > // The RISC-V version library support loading RISC-V32 and RISC-V64 PE/= CO=46=46 images. > +// The LoongArch version library support loading LoongArch32 and Loong= Arch64 PE/CO=46=46 images. > // > // Caution: This module requires additional review when modified. > // This library will have external input - PE/CO=46=46 image. > =40=40 -14,6 +15,7 =40=40 > // Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. > > // Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<= BR> > // Portions Copyright (c) 2020, Hewlett Packard Enterprise Development = LP. All rights reserved.
> +// Portions Copyright (c) 2022, Loongson Technology Corporation Limite= d. All rights reserved.
> // > // SPDX-License-Identifier: BSD-2-Clause-Patent > // > diff --git a/MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoaderEx.c b/= MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoaderEx.c > new file mode 100644 > index 0000000000..417096f334 > --- /dev/null > +++ b/MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoaderEx.c > =40=40 -0,0 +1,137 =40=40 > +/** =40file > > + PE/Coff loader for LoongArch PE image > + > + Copyright (c) 2022, Loongson Technology Corporation Limited. All righ= ts reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +=23include =22BasePeCoffLibInternals.h=22 > +=23include > + > +/** > + Performs an LoongArch specific relocation fixup and is a no-op on oth= er > + instruction sets. > + > + =40param=5Bin=5D Reloc Pointer to the relocation record. > + =40param=5Bin, out=5D =46ixup Pointer to the address to fix up. > + =40param=5Bin, out=5D =46ixupData Pointer to a buffer to log the fixu= ps. > + =40param=5Bin=5D Adjust The offset to adjust the fixup. > + > + =40return Status code. > + > +**/ > +RETURN=5FSTATUS > +PeCoffLoaderRelocateImageEx ( > + IN UINT16 *Reloc, > + IN OUT CHAR8 *=46ixup, > + IN OUT CHAR8 **=46ixupData, > + IN UINT64 Adjust > + ) > +=7B > + UINT8 RelocType; > + UINT64 Value; > + UINT64 Tmp1; > + UINT64 Tmp2; > + > + RelocType =3D (*Reloc) >> 12; > + Value =3D 0; > + Tmp1 =3D 0; > + Tmp2 =3D 0; > + > + switch (RelocType) =7B > + case E=46I=5FIMAGE=5FREL=5FBASED=5FLOONGARCH64=5FMARK=5FLA: > + // The next four instructions are used to load a 64 bit address, relo= cate all of them > + Value =3D (*(UINT32 *)=46ixup & 0x1ffffe0) << 7 =7C // lu12i.w 20bits= from bit5 > + (*((UINT32 *)=46ixup + 1) & 0x3ffc00) >> 10; // ori 12bits from bit10= > + Tmp1 =3D *((UINT32 *)=46ixup + 2) & 0x1ffffe0; // lu32i.d 20bits from= bit5 > + Tmp2 =3D *((UINT32 *)=46ixup + 3) & 0x3ffc00; // lu52i.d 12bits from = bit10 > + Value =3D Value =7C (Tmp1 << 27) =7C (Tmp2 << 42); > + Value +=3D Adjust; > + > + *(UINT32 *)=46ixup =3D (*(UINT32 *)=46ixup & =7E0x1ffffe0) =7C (((Val= ue >> 12) & 0xfffff) << 5); > + if (*=46ixupData =21=3D NULL) =7B > + *=46ixupData =3D ALIGN=5FPOINTER (*=46ixupData, sizeof (UINT32)); > + *(UINT32 *)(*=46ixupData) =3D *(UINT32 *)=46ixup; > + *=46ixupData =3D *=46ixupData + sizeof (UINT32); > + =7D > + > + =46ixup +=3D sizeof (UINT32); > + *(UINT32 *)=46ixup =3D (*(UINT32 *)=46ixup & =7E0x3ffc00) =7C ((Value= & 0xfff) << 10); > + if (*=46ixupData =21=3D NULL) =7B > + *=46ixupData =3D ALIGN=5FPOINTER (*=46ixupData, sizeof (UINT32)); > + *(UINT32 *)(*=46ixupData) =3D *(UINT32 *)=46ixup; > + *=46ixupData =3D *=46ixupData + sizeof (UINT32); > + =7D > + > + =46ixup +=3D sizeof (UINT32); > + *(UINT32 *)=46ixup =3D (*(UINT32 *)=46ixup & =7E0x1ffffe0) =7C (((Val= ue >> 32) & 0xfffff) << 5); > + if (*=46ixupData =21=3D NULL) =7B > + *=46ixupData =3D ALIGN=5FPOINTER (*=46ixupData, sizeof (UINT32)); > + *(UINT32 *)(*=46ixupData) =3D *(UINT32 *)=46ixup; > + *=46ixupData =3D *=46ixupData + sizeof (UINT32); > + =7D > + > + =46ixup +=3D sizeof (UINT32); > + *(UINT32 *)=46ixup =3D (*(UINT32 *)=46ixup & =7E0x3ffc00) =7C (((Valu= e >> 52) & 0xfff) << 10); > + if (*=46ixupData =21=3D NULL) =7B > + *=46ixupData =3D ALIGN=5FPOINTER (*=46ixupData, sizeof (UINT32)); > + *(UINT32 *)(*=46ixupData) =3D *(UINT32 *)=46ixup; > + *=46ixupData =3D *=46ixupData + sizeof (UINT32); > + =7D > + > + break; > + default: > + return RETURN=5FUNSUPPORTED; > + =7D > + > + return RETURN=5FSUCCESS; > +=7D > + > +/** > + Returns TRUE if the machine type of PE/CO=46=46 image is supported. S= upported > + does not mean the image can be executed it means the PE/CO=46=46 load= er supports > + loading and relocating of the image type. It's up to the caller to su= pport > + the entry point. > + > + =40param=5Bin=5D Machine Machine type from the PE Header. > + > + =40return TRUE if this PE/CO=46=46 loader can load the image > + > +**/ > +BOOLEAN > +PeCoffLoaderImage=46ormatSupported ( > + IN UINT16 Machine > + ) > +=7B > + if (Machine =3D=3D IMAGE=5F=46ILE=5FMACHINE=5FLOONGARCH64) =7B > + return TRUE; > + =7D > + > + return =46ALSE; > +=7D > + > +/** > + Performs an LOONGARCH-based specific re-relocation fixup and is a no-= op on other > + instruction sets. This is used to re-relocated the image into the E=46= I virtual > + space for runtime calls. > + > + =40param=5Bin=5D Reloc The pointer to the relocation record. > + =40param=5Bin, out=5D =46ixup The pointer to the address to fix up. > + =40param=5Bin, out=5D =46ixupData The pointer to a buffer to log the = fixups. > + =40param=5Bin=5D Adjust The offset to adjust the fixup. > + > + =40return Status code. > + > +**/ > +RETURN=5FSTATUS > +PeHotRelocateImageEx ( > + IN UINT16 *Reloc, > + IN OUT CHAR8 *=46ixup, > + IN OUT CHAR8 **=46ixupData, > + IN UINT64 Adjust > + ) > +=7B > + // To check > + return PeCoffLoaderRelocateImageEx (Reloc, =46ixup, =46ixupData, Adju= st); > +=7D > -- > 2.27.0 > --632d5dc4_3a4fcd4a_dbe1 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Hi Mike, Liming and Zhiguang,
This patch has not been reviewed, would you= please review it=3F


Thanks,<= br>Chao
--------

On 9=E6=9C=88 14 2022, at 5:41 =E4=B8=8B=E5=8D=88,= Chao Li <lichao=40loongson.cn> wrote:
R= E=46: https://bugzilla.tianocore.org/show=5Fbug.cgi=3Fid=3D4053

=
Add LoongArch image relocation.

Cc: Michael D Kinney &= lt;michael.d.kinney=40intel.com>
Cc: Liming Gao <gaolimin= g=40byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu=40inte= l.com>

Signed-off-by: Chao Li <lichao=40loongson.cn&g= t;
Co-authored-by: Baoqi Zhang <zhangbaoqi=40loongson.cn>=
---
MdePkg/Library/BasePeCoffLib/BasePeCoff.c =7C 3 = +-
.../Library/BasePeCoffLib/BasePeCoffLib.inf =7C 5 +
.../Library/BasePeCoffLib/BasePeCoffLib.uni =7C 2 +
.../BaseP= eCoffLib/LoongArch/PeCoffLoaderEx.c =7C 137 ++++++++++++++++++
= 4 files changed, 146 insertions(+), 1 deletion(-)
create mode 1= 00644 MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoaderEx.c

diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Librar= y/BasePeCoffLib/BasePeCoff.c
index 6d8d9faeb8..97a8aaf8c7 10064= 4
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++= b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
=40=40 -1,6 +1,6 =40= =40
/** =40file

Base PE/CO=46=46 loader supports = loading any PE32/PE32+ or TE image, but

- only supports rel= ocating IA32, x64, IP=46, ARM, RISC-V and EBC images.

+ onl= y supports relocating IA32, x64, IP=46, ARM, RISC-V, LoongArch and EBC im= ages.



Caution: This file requires additional review= when modified.

This library will have external input - PE/= CO=46=46 image.

=40=40 -18,6 +18,7 =40=40
Copyrig= ht (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2009, Apple Inc. All rights rese= rved.<BR>

Portions Copyright (c) 2020, Hewlett Packar= d Enterprise Development LP. All rights reserved.<BR>

+ Portions Copyright (c) 2022, Loongson Technology Corporation Limited. = All rights reserved.<BR>

SPDX-License-Identifier: BSD= -2-Clause-Patent



**/

diff --git a/Mde= Pkg/Library/BasePeCoffLib/BasePeCoffLib.inf b/MdePkg/Library/BasePeCoffLi= b/BasePeCoffLib.inf
index 110b6d5a09..3b8b8eb191 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+++ b/M= dePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
=40=40 -4,6 +4,7 = =40=40
=23 The IA32 version library support loading IA32, X64 a= nd EBC PE/CO=46=46 images.

=23 The X64 version library supp= ort loading IA32, X64 and EBC PE/CO=46=46 images.

=23 The R= ISC-V version library support loading RISC-V images.

+=23 T= he LoongArch version library support loading LoongArch images.

<= div>=23
=23 Caution: This module requires additional review= when modified.

=23 This library will have external input -= PE/CO=46=46 image.

=40=40 -13,6 +14,7 =40=40
=23= Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR= >

=23 Portions copyright (c) 2008 - 2009, Apple Inc. All= rights reserved.<BR>

=23 Portions Copyright (c) 2020= , Hewlett Packard Enterprise Development LP. All rights reserved.<BR&g= t;

+=23 Portions Copyright (c) 2022, Loongson Technology Co= rporation Limited. All rights reserved.<BR>

=23
=
=23 SPDX-License-Identifier: BSD-2-Clause-Patent

=23=

=40=40 -46,6 +48,9 =40=40
=5BSources.RISCV64=5D<= /div>
RiscV/PeCoffLoaderEx.c



+=5BSources.LO= ONGARCH64=5D

+ LoongArch/PeCoffLoaderEx.c

+
=5BPackages=5D

MdePkg/MdePkg.dec


=
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni b/Md= ePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
index 55417029f2..= 1f731344e1 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff= Lib.uni
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
=40=40 -5,6 +5,7 =40=40
// The IA32 version library sup= port loading IA32, X64 and EBC PE/CO=46=46 images.

// The X= 64 version library support loading IA32, X64 and EBC PE/CO=46=46 images.<= /div>
// The RISC-V version library support loading RISC-V32 and = RISC-V64 PE/CO=46=46 images.

+// The LoongArch version libr= ary support loading LoongArch32 and LoongArch64 PE/CO=46=46 images.
=
//

// Caution: This module requires additional rev= iew when modified.

// This library will have external input= - PE/CO=46=46 image.

=40=40 -14,6 +15,7 =40=40
/= / Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<B= R>

// Portions copyright (c) 2008 - 2009, Apple Inc. All= rights reserved.<BR>

// Portions Copyright (c) 2020,= Hewlett Packard Enterprise Development LP. All rights reserved.<BR>= ;

+// Portions Copyright (c) 2022, Loongson Technology Corp= oration Limited. All rights reserved.<BR>

//
// SPDX-License-Identifier: BSD-2-Clause-Patent

//
diff --git a/MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoa= derEx.c b/MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoaderEx.c
new file mode 100644
index 0000000000..417096f334
= --- /dev/null
+++ b/MdePkg/Library/BasePeCoffLib/LoongArch/PeCo= ffLoaderEx.c
=40=40 -0,0 +1,137 =40=40
+/** =40file
+ PE/Coff loader for LoongArch PE image

+
+ Copyright (c) 2022, Loongson Technology Corporation Limited. = All rights reserved.<BR>

+

+ SPDX-Licen= se-Identifier: BSD-2-Clause-Patent

+**/

+
+=23include =22BasePeCoffLibInternals.h=22

+=23i= nclude <Library/BaseLib.h>

+

+/**
=
+ Performs an LoongArch specific relocation fixup and is a no-op= on other

+ instruction sets.

+

+ =40param=5Bin=5D Reloc Pointer to the relocation record.

+ =40param=5Bin, out=5D =46ixup Pointer to the address to fix up.
<= br>
+ =40param=5Bin, out=5D =46ixupData Pointer to a buffer to log th= e fixups.

+ =40param=5Bin=5D Adjust The offset to adjust th= e fixup.

+

+ =40return Status code.

=
+

+**/

+RETURN=5FSTATUS

+P= eCoffLoaderRelocateImageEx (

+ IN UINT16 *Reloc,

<= div>+ IN OUT CHAR8 *=46ixup,

+ IN OUT CHAR8 **=46ixupData,<= /div>
+ IN UINT64 Adjust

+ )

+=7B
+ UINT8 RelocType;

+ UINT64 Value;

+ UINT64 Tmp1;

+ UINT64 Tmp2;

+

+ RelocType =3D (*Reloc) >> 12;

+ Value =3D 0;
+ Tmp1 =3D 0;

+ Tmp2 =3D 0;

+
=
+ switch (RelocType) =7B

+ case E=46I=5FIMAGE=5FRE= L=5FBASED=5FLOONGARCH64=5FMARK=5FLA:

+ // The next four ins= tructions are used to load a 64 bit address, relocate all of them
+ Value =3D (*(UINT32 *)=46ixup & 0x1ffffe0) << 7 =7C //= lu12i.w 20bits from bit5

+ (*((UINT32 *)=46ixup + 1) &= 0x3ffc00) >> 10; // ori 12bits from bit10

+ Tmp1 =3D= *((UINT32 *)=46ixup + 2) & 0x1ffffe0; // lu32i.d 20bits from bit5
+ Tmp2 =3D *((UINT32 *)=46ixup + 3) & 0x3ffc00; // lu52i.= d 12bits from bit10

+ Value =3D Value =7C (Tmp1 << 27= ) =7C (Tmp2 << 42);

+ Value +=3D Adjust;

+

+ *(UINT32 *)=46ixup =3D (*(UINT32 *)=46ixup & =7E0= x1ffffe0) =7C (((Value >> 12) & 0xfffff) << 5);

=
+ if (*=46ixupData =21=3D NULL) =7B

+ *=46ixupData =3D= ALIGN=5FPOINTER (*=46ixupData, sizeof (UINT32));

+ *(UINT3= 2 *)(*=46ixupData) =3D *(UINT32 *)=46ixup;

+ *=46ixupData =3D= *=46ixupData + sizeof (UINT32);

+ =7D

+
+ =46ixup +=3D sizeof (UINT32);

+ *(UINT32 *)=46i= xup =3D (*(UINT32 *)=46ixup & =7E0x3ffc00) =7C ((Value & 0xfff) &= lt;< 10);

+ if (*=46ixupData =21=3D NULL) =7B

<= div>+ *=46ixupData =3D ALIGN=5FPOINTER (*=46ixupData, sizeof (UINT32));
+ *(UINT32 *)(*=46ixupData) =3D *(UINT32 *)=46ixup;
+ *=46ixupData =3D *=46ixupData + sizeof (UINT32);

+ = =7D

+

+ =46ixup +=3D sizeof (UINT32);
+ *(UINT32 *)=46ixup =3D (*(UINT32 *)=46ixup & =7E0x1ffffe0) =7C= (((Value >> 32) & 0xfffff) << 5);

+ if (*=46= ixupData =21=3D NULL) =7B

+ *=46ixupData =3D ALIGN=5FPOINTE= R (*=46ixupData, sizeof (UINT32));

+ *(UINT32 *)(*=46ixupDa= ta) =3D *(UINT32 *)=46ixup;

+ *=46ixupData =3D *=46ixupData= + sizeof (UINT32);

+ =7D

+

+ =46= ixup +=3D sizeof (UINT32);

+ *(UINT32 *)=46ixup =3D (*(UINT= 32 *)=46ixup & =7E0x3ffc00) =7C (((Value >> 52) & 0xfff) &l= t;< 10);

+ if (*=46ixupData =21=3D NULL) =7B

+ *=46ixupData =3D ALIGN=5FPOINTER (*=46ixupData, sizeof (UINT32));
+ *(UINT32 *)(*=46ixupData) =3D *(UINT32 *)=46ixup;

=
+ *=46ixupData =3D *=46ixupData + sizeof (UINT32);

+ =7D=

+

+ break;

+ default:
+ return RETURN=5FUNSUPPORTED;

+ =7D

+<= /div>
+ return RETURN=5FSUCCESS;

+=7D

+

+/**

+ Returns TRUE if the machine type of= PE/CO=46=46 image is supported. Supported

+ does not mean = the image can be executed it means the PE/CO=46=46 loader supports
<= br>
+ loading and relocating of the image type. It's up to the caller= to support

+ the entry point.

+

+ =40param=5Bin=5D Machine Machine type from the PE Header.

+

+ =40return TRUE if this PE/CO=46=46 loader can load t= he image

+

+**/

+BOOLEAN
<= br>
+PeCoffLoaderImage=46ormatSupported (

+ IN UINT16 M= achine

+ )

+=7B

+ if (Machine =3D= =3D IMAGE=5F=46ILE=5FMACHINE=5FLOONGARCH64) =7B

+ return TR= UE;

+ =7D

+

+ return =46ALSE;
+=7D

+

+/**

+ Perf= orms an LOONGARCH-based specific re-relocation fixup and is a no-op on ot= her

+ instruction sets. This is used to re-relocated the im= age into the E=46I virtual

+ space for runtime calls.
=
+

+ =40param=5Bin=5D Reloc The pointer to the relo= cation record.

+ =40param=5Bin, out=5D =46ixup The pointer = to the address to fix up.

+ =40param=5Bin, out=5D =46ixupDa= ta The pointer to a buffer to log the fixups.

+ =40param=5B= in=5D Adjust The offset to adjust the fixup.

+

+ =40return Status code.

+

+**/

+RETURN=5FSTATUS

+PeHotRelocateImageEx (

+= IN UINT16 *Reloc,

+ IN OUT CHAR8 *=46ixup,

+= IN OUT CHAR8 **=46ixupData,

+ IN UINT64 Adjust

+ )

+=7B

+ // To check

+ ret= urn PeCoffLoaderRelocateImageEx (Reloc, =46ixup, =46ixupData, Adjust);
+=7D

--
2.27.0
--632d5dc4_3a4fcd4a_dbe1--