From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web11.1838.1571135495279883466 for ; Tue, 15 Oct 2019 03:31:35 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=fNW3ULjc; spf=pass (domain: linaro.org, ip: 209.85.221.66, mailfrom: leif.lindholm@linaro.org) Received: by mail-wr1-f66.google.com with SMTP id o28so555355wro.7 for ; Tue, 15 Oct 2019 03:31:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=8Z4nJRcepukJuSu1ppTCtFytyVlIZyJ5iypjEWWMkUE=; b=fNW3ULjcDllwOmKkIdMrD7k+c3CaC+lp2/0FMrYyvnkJglIos7uR0U3pLJADFc9UUW s9KLkyWrxmdU7W4YpI2KNA22h1i0lNf0zqhm6JvtrIkr5yGNtoSQAJn9/0WcsZ8hPR4y 8ufntI9FWqtKmd0B+AbU4CfJUrEtPPkUUnRMVI3ckOO1oyRno+FQjSVX8R+ACRAHGyqt 15dmXdgfRcmr9dqeTieQ5YGHkTgVpefqR/Nql7p9+Mwxgf+KlcJwpDGw5lz3kISFFbJ/ T3gvJ4nybfw3BpKCNWTNMxLnt7g1KQEiWaPEba4775W9/6ZOfQp76xm6rs0OZjfXNRTA Qygw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=8Z4nJRcepukJuSu1ppTCtFytyVlIZyJ5iypjEWWMkUE=; b=R0vOZhvh5Bb1FlV10rz7dUvI28ANZCL8/fRxn26ooZT21VZvc+nZKboKgAgctpxJoF eyQ8JYdqLDCCS9Kew0IJrITOPEbABDm45mJuvPjNMun/j39EfVKdCrX+cJpQH4803eVe 8Ua4ZolyCEkq+P2GuT8uOC1b6GTRv/3j/wZrSOYU8piF6HZ4+3IU+jxn3w2JndwFFbvz cbKwYOZ8F/4t2FupXJmugGN5QpRsFDwUUGoxhyUsPRDYLYyQkMpUyoz1AT7TcqEvV9JW Pb07VtqA9xNvfWVOCYXMXjQ5brx7bhTFA2YbLABJ62S/JFn1WjPYvrVKBZBZ6ttI7sOA 2b0w== X-Gm-Message-State: APjAAAXEENlaFj9tK6Q3bGKp1hYudqGyPcWlCpt01cM8Tu4sLuQfYQKG pjYlCI0uoMNnfuEtiH+RLeWjZg== X-Google-Smtp-Source: APXvYqyVS1BrFjcKloyaMDMr2lEdYarHgu11XEdPNBEwUKx6QFawZelBtmNM4zgRRweVKF20qbRjtQ== X-Received: by 2002:adf:f3c9:: with SMTP id g9mr19675357wrp.7.1571135493713; Tue, 15 Oct 2019 03:31:33 -0700 (PDT) Return-Path: Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id n8sm25624133wma.7.2019.10.15.03.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 03:31:32 -0700 (PDT) Date: Tue, 15 Oct 2019 11:31:31 +0100 From: "Leif Lindholm" To: "Chang, Abner (HPS SW/FW Technologist)" Cc: "devel@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. Message-ID: <20191015103131.GI25504@bivouac.eciton.net> References: <1569198715-31552-1-git-send-email-abner.chang@hpe.com> <1569198715-31552-12-git-send-email-abner.chang@hpe.com> <20190926234620.GM25504@bivouac.eciton.net> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Oct 15, 2019 at 04:02:47AM +0000, Chang, Abner (HPS SW/FW Technologist) wrote: > > -----Original Message----- > > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > > Leif Lindholm > > Sent: Friday, September 27, 2019 7:46 AM > > To: devel@edk2.groups.io; Chang, Abner (HPS SW/FW Technologist) > > > > 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 > > > --- > > > 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.
> > > Portions copyright (c) 2008 - 2009, Apple Inc. All rights > > > reserved.
> > > + Portions Copyright (c) 2016, Hewlett Packard Enterprise Development > > > + LP. All rights reserved.
> > > 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.
# Portions copyright (c) 2008 - 2009, Apple Inc. All > > > rights reserved.
> > > +# Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All > > > +rights reserved.
> > > # > > > # 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.
// Portions copyright (c) 2008 - 2009, Apple Inc. All > > > rights reserved.
> > > +// Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All > > > +rights reserved.
> > > // > > > // 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.
> > > + Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All > > > + rights reserved.
> > > > 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.
> > > + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include > > > +"BasePeCoffLibInternals.h" > > > +#include > > > + > > > +// > > > +// RISC-V definition. > > > +// > > > +#define RV_X(x, s, n) (((x) >> (s)) & ((1<<(n))-1)) #define > > > +RISCV_IMM_BITS 12 #define RISCV_IMM_REACH > > (1LL< > > +#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". Best Regards, Leif