public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Abner Chang" <abner.chang@hpe.com>
To: Sunil V L <sunilvl@ventanamicro.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "sunil.vl@gmail.com" <sunil.vl@gmail.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Bob Feng <bob.c.feng@intel.com>,
	Yuwei Chen <yuwei.chen@intel.com>, Pete Batard <pete@akeo.ie>,
	"Schaefer, Daniel" <daniel.schaefer@hpe.com>
Subject: Re: [PATCH] BaseTools GenFw: Add support for R_RISCV_PCREL_LO12_S relocation
Date: Tue, 13 Jul 2021 02:44:33 +0000	[thread overview]
Message-ID: <CS1PR8401MB11443643DBBB8C97744753FDFF149@CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20210710063114.4278-1-sunilvl@ventanamicro.com>

Acked-by: Abner Chang <abner.chang@hpe.com>

> -----Original Message-----
> From: Sunil V L [mailto:sunilvl@ventanamicro.com]
> Sent: Saturday, July 10, 2021 2:31 PM
> To: devel@edk2.groups.io
> Cc: sunil.vl@gmail.com; Sunil V L <sunilvl@ventanamicro.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Bob Feng <bob.c.feng@intel.com>; Yuwei
> Chen <yuwei.chen@intel.com>; Pete Batard <pete@akeo.ie>; Chang, Abner
> (HPS SW/FW Technologist) <abner.chang@hpe.com>; Schaefer, Daniel
> <daniel.schaefer@hpe.com>
> Subject: [PATCH] BaseTools GenFw: Add support for
> R_RISCV_PCREL_LO12_S relocation
> 
> Ref:
> INVALID URI REMOVED
> d=3459__;!!NpxR!zrGTHXfzHm6WE6VZ2rABQ0yFTgu7frG5J213efKk-
> TmOGcp_9TSXv8E3b_XlNzo$
> 
> This patch adds support for R_RISCV_PCREL_LO12_S relocation type.
> The logic is same as existing R_RISCV_PCREL_LO12_I relocation
> except the difference between load vs store instruction formats.
> 
> Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
> 
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Bob Feng <bob.c.feng@intel.com>
> Cc: Yuwei Chen <yuwei.chen@intel.com>
> Cc: Pete Batard <pete@akeo.ie>
> Cc: Abner Chang <abner.chang@hpe.com>
> Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
> ---
>  BaseTools/Source/C/GenFw/Elf64Convert.c | 55
> +++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)
> 
> diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c
> b/BaseTools/Source/C/GenFw/Elf64Convert.c
> index 3d7e20aaff..0bb3ead228 100644
> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
> @@ -557,6 +557,60 @@ WriteSectionRiscV64 (
>      Value = (UINT32)(RV_X(*(UINT32 *)mRiscVPass1Targ, 12, 20));
>      break;
> 
> +  case R_RISCV_PCREL_LO12_S:
> +    if (mRiscVPass1Targ != NULL && mRiscVPass1Sym != NULL &&
> mRiscVPass1SymSecIndex != 0) {
> +      int i;
> +      Value2 = (UINT32)(RV_X(*(UINT32 *)mRiscVPass1Targ, 12, 20));
> +
> +      Value = ((UINT32)(RV_X(*(UINT32 *)Targ, 25, 7)) << 5);
> +      Value = (Value | (UINT32)(RV_X(*(UINT32 *)Targ, 7, 5)));
> +
> +      if(Value & (RISCV_IMM_REACH/2)) {
> +        Value |= ~(RISCV_IMM_REACH-1);
> +      }
> +      Value = Value - (UINT32)mRiscVPass1Sym->sh_addr +
> mCoffSectionsOffset[mRiscVPass1SymSecIndex];
> +
> +      if(-2048 > (INT32)Value) {
> +        i = (((INT32)Value * -1) / 4096);
> +        Value2 -= i;
> +        Value += 4096 * i;
> +        if(-2048 > (INT32)Value) {
> +          Value2 -= 1;
> +          Value += 4096;
> +        }
> +      }
> +      else if( 2047 < (INT32)Value) {
> +        i = (Value / 4096);
> +        Value2 += i;
> +        Value -= 4096 * i;
> +        if(2047 < (INT32)Value) {
> +          Value2 += 1;
> +          Value -= 4096;
> +        }
> +      }
> +
> +      // Update the IMM of SD instruction
> +      //
> +      // |31      25|24  20|19  15|14   12 |11      7|6     0|
> +      // |-------------------------------------------|-------|
> +      // |imm[11:5] | rs2  | rs1  | funct3 |imm[4:0] | opcode|
> +      //  ---------------------------------------------------
> +
> +      // First Zero out current IMM
> +      *(UINT32 *)Targ &= ~0xfe000f80;
> +
> +      // Update with new IMM
> +      *(UINT32 *)Targ |= (RV_X(Value, 5, 7) << 25);
> +      *(UINT32 *)Targ |= (RV_X(Value, 0, 5) << 7);
> +
> +      // Update previous instruction
> +      *(UINT32 *)mRiscVPass1Targ = (RV_X(Value2, 0, 20)<<12) |
> (RV_X(*(UINT32 *)mRiscVPass1Targ, 0, 12));
> +    }
> +    mRiscVPass1Sym = NULL;
> +    mRiscVPass1Targ = NULL;
> +    mRiscVPass1SymSecIndex = 0;
> +    break;
> +
>    case R_RISCV_PCREL_LO12_I:
>      if (mRiscVPass1Targ != NULL && mRiscVPass1Sym != NULL &&
> mRiscVPass1SymSecIndex != 0) {
>        int i;
> @@ -1587,6 +1641,7 @@ WriteRelocations64 (
>              case R_RISCV_PCREL_HI20:
>              case R_RISCV_GOT_HI20:
>              case R_RISCV_PCREL_LO12_I:
> +            case R_RISCV_PCREL_LO12_S:
>                break;
> 
>              default:
> --
> 2.32.0


  parent reply	other threads:[~2021-07-13  2:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-10  6:31 [PATCH] BaseTools GenFw: Add support for R_RISCV_PCREL_LO12_S relocation Sunil V L
2021-07-12 11:51 ` Pete Batard
2021-07-12 13:39 ` 回复: " gaoliming
2021-07-13  2:44 ` Abner Chang [this message]
2021-07-13  9:27 ` Daniel Schaefer
2021-07-13 10:14   ` Sunil V L
2021-07-20  5:48     ` 回复: " gaoliming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CS1PR8401MB11443643DBBB8C97744753FDFF149@CS1PR8401MB1144.NAMPRD84.PROD.OUTLOOK.COM \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox