public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nelson Chu <nelson.chu@sifive.com>
To: binutils@sourceware.org,	jrtc27@jrtc27.com
Cc: jimw@sifive.com,	kito.cheng@sifive.com,	palmerdabbelt@google.com
Subject: [PATCH 1/2] RISC-V: Add description for RISC-V Modifiers to as doc.
Date: Tue, 03 Mar 2020 10:22:00 -0000	[thread overview]
Message-ID: <1583230959-11401-2-git-send-email-nelson.chu@sifive.com> (raw)
In-Reply-To: <1583230959-11401-1-git-send-email-nelson.chu@sifive.com>

	gas/
	* doc/c-riscv.texi (relocation modifiers): Add documentation.
	(RISC-V-Formats): Update the section name from "Instruction Formats"
	to "RISC-V Instruction Formats".
---
 gas/doc/c-riscv.texi | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 102 insertions(+), 1 deletion(-)

diff --git a/gas/doc/c-riscv.texi b/gas/doc/c-riscv.texi
index 599b5cf..8212a17 100644
--- a/gas/doc/c-riscv.texi
+++ b/gas/doc/c-riscv.texi
@@ -17,6 +17,7 @@
 @menu
 * RISC-V-Options::        RISC-V Options
 * RISC-V-Directives::     RISC-V Directives
+* RISC-V-Modifiers::      RISC-V Assembler Modifiers
 * RISC-V-Formats::        RISC-V Instruction Formats
 * RISC-V-ATTRIBUTE::      RISC-V Object Attribute
 @end menu
@@ -207,8 +208,108 @@ The @var{tag} is either an attribute number, or one of the following:
 
 @end table
 
+@node RISC-V-Modifiers
+@section RISC-V Assembler Modifiers
+
+RISC-V assembler supports following modifiers for relocatable address
+used in RISC-V instruction operands.  However, we also support some
+pseudo instructions to reduce the use of error-prone for these modifiers.
+
+@table @code
+@item %lo(@var{symbol})
+The low 12-bit of absolute address for @var{symbol}.
+
+@item %hi(@var{symbol})
+The high 20-bit of absolute address for @var{symbol}.  This is usually
+used with the %lo to represent a 32-bit absolute address.
+
+@smallexample
+	lui             a0, %hi(@var{symbol})     // R_RISCV_HI20
+	addi/load/store a0, a0, %lo(@var{symbol}) // R_RISCV_LO12_I/S
+@end smallexample
+
+@item %pcrel_lo(@var{label})
+The low 12-bit of relative address between pc and @var{symbol}.
+The @var{symbol} is related to the high part instrcution which marked
+by @var{label}.
+
+@item %pcrel_hi(@var{symbol})
+The high 20-bit of relative address between pc and @var{symbol}.
+This is usually used with the %pcrel_lo to represent a 4GB pc-relative range.
+
+@smallexample
+@var{label}:
+	auipc           a0, %pcrel_hi(@var{symbol})    // R_RISCV_PCREL_HI20
+	addi/load/store a0, a0, %pcrel_lo(@var{label}) // R_RISCV_PCREL_LO12_I/S
+@end smallexample
+
+Or you can use the pseudo lla/lw/sw/... instruction to do this.
+
+@smallexample
+	lla  a0, @var{symbol}
+@end smallexample
+
+@item %tprel_add(@var{symbol}
+This is used purely to associate the R_RISCV_TPREL_ADD relocation for
+TLS relaxation.
+
+@item %tprel_lo(@var{symbol})
+The low 12-bit of relative address between tp and @var{symbol}
+
+@item %tprel_hi(@var{symbol})
+The high 20-bit of relative address between tp and @var{symbol}.  This is
+usually used with the %tprel_lo and %tprel_add to access the thread local
+variable @var{symbol} in TLS Local Exec.
+
+@smallexample
+	lui        a5, %tprel_hi(@var{symbol})          // R_RISCV_TPREL_HI20
+	add        a5, a5, tp, %tprel_add(@var{symbol}) // R_RISCV_TPREL_ADD
+	load/store t0, %tprel_lo(@var{symbol})(a5)      // R_RISCV_TPREL_LO12_I/S
+@end smallexample
+
+@item %tls_ie_pcrel_hi(@var{symbol})
+The high 20-bit of relative address between pc and GOT entry.  It is usually
+used with the %pcrel_lo to access the thread local variable @var{symbol} in
+TLS Inital Exec.
+
+@smallexample
+	la.tls.ie  a5, @var{symbol}
+	add        a5, a5, tp
+	load/store t0, 0(a5)
+@end smallexample
+
+The pseudo la.tls.ie instruction can be expended to
+
+@smallexample
+@var{label}:
+	auipc a5, %tls_ie_pcrel_hi(@var{symbol}) // R_RISCV_TLS_GOT_HI20
+	ld/lw a5, %pcrel_lo(@var{label})(a5)     // R_RISCV_PCREL_LO12_I/S
+@end smallexample
+
+@item %tls_gd_pcrel_hi(@var{symbol})
+The high 20-bit of relative address between pc and GOT entry.  It is usually
+used with the %pcrel_lo to access the thread local variable @var{symbol} in
+TLS Global Dynamic.
+
+@smallexample
+	la.tls.gd  a0, @var{symbol}
+	call       __tls_get_addr@@plt
+	mv         a5, a0
+	load/store t0, 0(a5)
+@end smallexample
+
+The pseudo la.tls.gd instruction can be expended to
+
+@smallexample
+@var{label}:
+	auipc a0, %tls_gd_pcrel_hi(@var{symbol}) // R_RISCV_TLS_GD_HI20
+	addi  a0, a0, %pcrel_lo(@var{label})     // R_RISCV_PCREL_LO12_I/S
+@end smallexample
+
+@end table
+
 @node RISC-V-Formats
-@section Instruction Formats
+@section RISC-V Instruction Formats
 @cindex instruction formats, risc-v
 @cindex RISC-V instruction formats
 
-- 
2.7.4

  reply	other threads:[~2020-03-03 10:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-03 10:22 [PATCH 0/2] Add description for the RISC-V relocatable modifiers in " Nelson Chu
2020-03-03 10:22 ` Nelson Chu [this message]
2020-03-03 22:12   ` [PATCH 1/2] RISC-V: Add description for RISC-V Modifiers to " Jim Wilson
2020-03-03 10:22 ` [PATCH 2/2] RISC-V: Support assembler modifier %got_pcrel_hi Nelson Chu
2020-03-03 22:16   ` Jim Wilson
2020-03-04  0:07     ` Fangrui Song
2020-03-04  1:54       ` Nelson Chu

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-all 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=1583230959-11401-2-git-send-email-nelson.chu@sifive.com \
    --to=nelson.chu@sifive.com \
    --cc=binutils@sourceware.org \
    --cc=jimw@sifive.com \
    --cc=jrtc27@jrtc27.com \
    --cc=kito.cheng@sifive.com \
    --cc=palmerdabbelt@google.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).