[edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 10/29] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code.

Abner Chang abner.chang at hpe.com
Tue Oct 15 10:56:27 UTC 2019



> -----Original Message-----
> From: devel at edk2.groups.io [mailto:devel at edk2.groups.io] On Behalf Of
> Leif Lindholm
> Sent: Tuesday, October 15, 2019 6:32 PM
> To: Chang, Abner (HPS SW/FW Technologist) <abner.chang at hpe.com>
> Cc: devel at edk2.groups.io
> Subject: Re: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 10/29]
> MdePkg/BasePeCoff: Add RISC-V PE/Coff related code.
> 
> On Tue, Oct 15, 2019 at 04:02:47AM +0000, Chang, Abner (HPS SW/FW
> Technologist) wrote:
> > > -----Original Message-----
> > > From: devel at edk2.groups.io [mailto:devel at edk2.groups.io] On Behalf
> > > Of Leif Lindholm
> > > Sent: Friday, September 27, 2019 7:46 AM
> > > To: devel at edk2.groups.io; Chang, Abner (HPS SW/FW Technologist)
> > > <abner.chang at hpe.com>
> > > Subject: Re: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 10/29]
> > > MdePkg/BasePeCoff: Add RISC-V PE/Coff related code.
> > >
> > > On Mon, Sep 23, 2019 at 08:31:36AM +0800, Abner Chang wrote:
> > > > Support RISC-V image relocation.
> > > >
> > > > Signed-off-by: Abner Chang <abner.chang at hpe.com>
> > > > ---
> > > >  MdePkg/Library/BasePeCoffLib/BasePeCoff.c          |   3 +-
> > > >  MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf     |   5 +
> > > >  MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni     |   2 +
> > > >  .../Library/BasePeCoffLib/BasePeCoffLibInternals.h |   1 +
> > > >  .../Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c   | 142
> > > +++++++++++++++++++++
> > > >  5 files changed, 152 insertions(+), 1 deletion(-)  create mode
> > > > 100644 MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
> > > >
> > > > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > > > b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > > > index 07bb62f..97e0ff4 100644
> > > > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > > > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > > > @@ -1,6 +1,6 @@
> > > >  /** @file
> > > >    Base PE/COFF loader supports loading any PE32/PE32+ or TE
> > > > image, but
> > > > -  only supports relocating IA32, x64, IPF, and EBC images.
> > > > +  only supports relocating IA32, x64, IPF, ARM, RISC-V and EBC images.
> > > >
> > > >    Caution: This file requires additional review when modified.
> > > >    This library will have external input - PE/COFF image.
> > > > @@ -17,6 +17,7 @@
> > > >
> > > >    Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
> > > >    Portions copyright (c) 2008 - 2009, Apple Inc. All rights
> > > > reserved.<BR>
> > > > +  Portions Copyright (c) 2016, Hewlett Packard Enterprise
> > > > + Development LP. All rights reserved.<BR>
> > > >    SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >
> > > >  **/
> > > > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
> > > > b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
> > > > index 395c140..b190494 100644
> > > > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
> > > > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
> > > > @@ -3,6 +3,7 @@
> > > >  #  The IPF version library supports loading IPF and EBC PE/COFF image.
> > > >  #  The IA32 version library support loading IA32, X64 and EBC
> > > > PE/COFF
> > > images.
> > > >  #  The X64 version library support loading IA32, X64 and EBC
> > > > PE/COFF
> > > images.
> > > > +#  The RISC-V version library support loading RISC-V images.
> > > >  #
> > > >  #  Caution: This module requires additional review when modified.
> > > >  #  This library will have external input - PE/COFF image.
> > > > @@ -11,6 +12,7 @@
> > > >  #
> > > >  #  Copyright (c) 2006 - 2018, Intel Corporation. All rights
> > > > reserved.<BR>  #  Portions copyright (c) 2008 - 2009, Apple Inc.
> > > > All rights reserved.<BR>
> > > > +#  Copyright (c) 2016, Hewlett Packard Enterprise Development LP.
> > > > +All rights reserved.<BR>
> > > >  #
> > > >  #  SPDX-License-Identifier: BSD-2-Clause-Patent  # @@ -41,6 +43,9
> > > > @@ [Sources.ARM]
> > > >    Arm/PeCoffLoaderEx.c
> > > >
> > > > +[Sources.RISCV64]
> > > > +  RiscV/PeCoffLoaderEx.c
> > > > +
> > > >  [Packages]
> > > >    MdePkg/MdePkg.dec
> > > >
> > > > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
> > > > b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
> > > > index b0ea702..8616ca3 100644
> > > > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
> > > > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
> > > > @@ -4,6 +4,7 @@
> > > >  // The IPF version library supports loading IPF and EBC PE/COFF image.
> > > >  // The IA32 version library support loading IA32, X64 and EBC
> > > > PE/COFF
> > > images.
> > > >  // The X64 version library support loading IA32, X64 and EBC
> > > > PE/COFF
> > > images.
> > > > +// The RISC-V version library support loading RISC-V32 and
> > > > +RISC-V64
> > > PE/COFF images.
> > > >  //
> > > >  // Caution: This module requires additional review when modified.
> > > >  // This library will have external input - PE/COFF image.
> > > > @@ -12,6 +13,7 @@
> > > >  //
> > > >  // Copyright (c) 2006 - 2018, Intel Corporation. All rights
> > > > reserved.<BR>  // Portions copyright (c) 2008 - 2009, Apple Inc.
> > > > All rights reserved.<BR>
> > > > +// Copyright (c) 2016, Hewlett Packard Enterprise Development LP.
> > > > +All rights reserved.<BR>
> > > >  //
> > > >  // SPDX-License-Identifier: BSD-2-Clause-Patent  // diff --git
> > > > a/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
> > > > b/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
> > > > index b74277f..9c33703 100644
> > > > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
> > > > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
> > > > @@ -2,6 +2,7 @@
> > > >    Declaration of internal functions in PE/COFF Lib.
> > > >
> > > >    Copyright (c) 2006 - 2010, Intel Corporation. All rights
> > > > reserved.<BR>
> > > > +  Copyright (c) 2016, Hewlett Packard Enterprise Development LP.
> > > > + All rights reserved.<BR>
> > >
> > > You only get to add copyright when you otherwise modify the file :)
> > >
> > > >    SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >
> > > >  **/
> > > > diff --git a/MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
> > > > b/MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
> > > > new file mode 100644
> > > > index 0000000..8eb37f9
> > > > --- /dev/null
> > > > +++ b/MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
> > > > @@ -0,0 +1,142 @@
> > > > +/** @file
> > > > +  PE/Coff loader for RISC-V PE image
> > > > +
> > > > +  Copyright (c) 2016, Hewlett Packard Enterprise Development LP.
> > > > +All rights reserved.<BR>
> > > > +  SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include
> > > > +"BasePeCoffLibInternals.h"
> > > > +#include <Library/BaseLib.h>
> > > > +
> > > > +//
> > > > +// RISC-V definition.
> > > > +//
> > > > +#define RV_X(x, s, n) (((x) >> (s)) & ((1<<(n))-1)) #define
> > > > +RISCV_IMM_BITS 12 #define RISCV_IMM_REACH
> > > (1LL<<RISCV_IMM_BITS)
> > > > +#define RISCV_CONST_HIGH_PART(VALUE) \
> > > > +  (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))
> > >
> > > This looked familiar, so I had a look.
> > > This block is copied around - it exists in:
> > > - BaseTools/Source/C/Common/PeCoffLoaderEx.c
> > > - BaseTools/Source/C/GenFw/Elf64Convert.c
> > > - MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
> > >
> > > This needs to be moved somewhere central and included elsewhere.
> > > BaseTools and MdePkg unfortunately duplicate a lot of stuff, but
> > > this still belongs in a common header file for either.
> >
> > I can consolidate that macro in two files under BaseTools, but not
> > consolidating macro in files in both MdePkg and BaseTools. BaseTools
> > and edk2 are two separate projects and could be built individually
> > based on my understanding.
> >
> > I have no idea how to leverage one header file from both projects and
> > I don't  go that far to address it.
> 
> Oh, indeed. This was me bemoaning the current state of things - not
> suggesting you need to fix it (beyond having only one copy for BaseTools and
> one copy for the platform code.).
> 
> I need to check my use of English subtleties:
> "belongs in a common header file for either" means "one for each".
Hah Hah. My bad.
Ok! Then it's much easier!  Let me see if I can put RISC-V specific macro into an existing header file or a new one.
> 
> Best Regards,
> 
> Leif
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#48998): https://edk2.groups.io/g/devel/message/48998
Mute This Topic: https://groups.io/mt/34258204/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list