Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

214 lines
8.7KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the GNU Assembler "as".
  4. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3
  7. or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, with no Front-Cover Texts, and with no
  9. Back-Cover Texts. A copy of the license is included in the
  10. section entitled "GNU Free Documentation License".
  11. -->
  12. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>RISC-V-Modifiers (Using as)</title>
  16. <meta name="description" content="RISC-V-Modifiers (Using as)">
  17. <meta name="keywords" content="RISC-V-Modifiers (Using as)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="RISC_002dV_002dDependent.html#RISC_002dV_002dDependent" rel="up" title="RISC-V-Dependent">
  25. <link href="RISC_002dV_002dFormats.html#RISC_002dV_002dFormats" rel="next" title="RISC-V-Formats">
  26. <link href="RISC_002dV_002dDirectives.html#RISC_002dV_002dDirectives" rel="prev" title="RISC-V-Directives">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.indentedblock {margin-right: 0em}
  31. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  32. blockquote.smallquotation {font-size: smaller}
  33. div.display {margin-left: 3.2em}
  34. div.example {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style: oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nolinebreak {white-space: nowrap}
  49. span.roman {font-family: initial; font-weight: normal}
  50. span.sansserif {font-family: sans-serif; font-weight: normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en">
  56. <a name="RISC_002dV_002dModifiers"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="RISC_002dV_002dFormats.html#RISC_002dV_002dFormats" accesskey="n" rel="next">RISC-V-Formats</a>, Previous: <a href="RISC_002dV_002dDirectives.html#RISC_002dV_002dDirectives" accesskey="p" rel="prev">RISC-V-Directives</a>, Up: <a href="RISC_002dV_002dDependent.html#RISC_002dV_002dDependent" accesskey="u" rel="up">RISC-V-Dependent</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
  60. </div>
  61. <hr>
  62. <a name="RISC_002dV-Assembler-Modifiers"></a>
  63. <h4 class="subsection">9.38.3 RISC-V Assembler Modifiers</h4>
  64. <p>The RISC-V assembler supports following modifiers for relocatable addresses
  65. used in RISC-V instruction operands. However, we also support some pseudo
  66. instructions that are easier to use than these modifiers.
  67. </p>
  68. <dl compact="compact">
  69. <dt><code>%lo(<var>symbol</var>)</code></dt>
  70. <dd><p>The low 12 bits of absolute address for <var>symbol</var>.
  71. </p>
  72. </dd>
  73. <dt><code>%hi(<var>symbol</var>)</code></dt>
  74. <dd><p>The high 20 bits of absolute address for <var>symbol</var>. This is usually
  75. used with the %lo modifier to represent a 32-bit absolute address.
  76. </p>
  77. <div class="smallexample">
  78. <pre class="smallexample"> lui a0, %hi(<var>symbol</var>) // R_RISCV_HI20
  79. addi a0, a0, %lo(<var>symbol</var>) // R_RISCV_LO12_I
  80. lui a0, %hi(<var>symbol</var>) // R_RISCV_HI20
  81. load/store a0, %lo(<var>symbol</var>)(a0) // R_RISCV_LO12_I/S
  82. </pre></div>
  83. </dd>
  84. <dt><code>%pcrel_lo(<var>label</var>)</code></dt>
  85. <dd><p>The low 12 bits of relative address between pc and <var>symbol</var>.
  86. The <var>symbol</var> is related to the high part instruction which is marked
  87. by <var>label</var>.
  88. </p>
  89. </dd>
  90. <dt><code>%pcrel_hi(<var>symbol</var>)</code></dt>
  91. <dd><p>The high 20 bits of relative address between pc and <var>symbol</var>.
  92. This is usually used with the %pcrel_lo modifier to represent a +/-2GB
  93. pc-relative range.
  94. </p>
  95. <div class="smallexample">
  96. <pre class="smallexample"><var>label</var>:
  97. auipc a0, %pcrel_hi(<var>symbol</var>) // R_RISCV_PCREL_HI20
  98. addi a0, a0, %pcrel_lo(<var>label</var>) // R_RISCV_PCREL_LO12_I
  99. <var>label</var>:
  100. auipc a0, %pcrel_hi(<var>symbol</var>) // R_RISCV_PCREL_HI20
  101. load/store a0, %pcrel_lo(<var>label</var>)(a0) // R_RISCV_PCREL_LO12_I/S
  102. </pre></div>
  103. <p>Or you can use the pseudo lla/lw/sw/... instruction to do this.
  104. </p>
  105. <div class="smallexample">
  106. <pre class="smallexample"> lla a0, <var>symbol</var>
  107. </pre></div>
  108. </dd>
  109. <dt><code>%got_pcrel_hi(<var>symbol</var>)</code></dt>
  110. <dd><p>The high 20 bits of relative address between pc and the GOT entry of
  111. <var>symbol</var>. This is usually used with the %pcrel_lo modifier to access
  112. the GOT entry.
  113. </p>
  114. <div class="smallexample">
  115. <pre class="smallexample"><var>label</var>:
  116. auipc a0, %got_pcrel_hi(<var>symbol</var>) // R_RISCV_GOT_HI20
  117. addi a0, a0, %pcrel_lo(<var>label</var>) // R_RISCV_PCREL_LO12_I
  118. <var>label</var>:
  119. auipc a0, %got_pcrel_hi(<var>symbol</var>) // R_RISCV_GOT_HI20
  120. load/store a0, %pcrel_lo(<var>label</var>)(a0) // R_RISCV_PCREL_LO12_I/S
  121. </pre></div>
  122. <p>Also, the pseudo la instruction with PIC has similar behavior.
  123. </p>
  124. </dd>
  125. <dt><code>%tprel_add(<var>symbol</var>)</code></dt>
  126. <dd><p>This is used purely to associate the R_RISCV_TPREL_ADD relocation for
  127. TLS relaxation. This one is only valid as the fourth operand to the normally
  128. 3 operand add instruction.
  129. </p>
  130. </dd>
  131. <dt><code>%tprel_lo(<var>symbol</var>)</code></dt>
  132. <dd><p>The low 12 bits of relative address between tp and <var>symbol</var>.
  133. </p>
  134. </dd>
  135. <dt><code>%tprel_hi(<var>symbol</var>)</code></dt>
  136. <dd><p>The high 20 bits of relative address between tp and <var>symbol</var>. This is
  137. usually used with the %tprel_lo and %tprel_add modifiers to access the thread
  138. local variable <var>symbol</var> in TLS Local Exec.
  139. </p>
  140. <div class="smallexample">
  141. <pre class="smallexample"> lui a5, %tprel_hi(<var>symbol</var>) // R_RISCV_TPREL_HI20
  142. add a5, a5, tp, %tprel_add(<var>symbol</var>) // R_RISCV_TPREL_ADD
  143. load/store t0, %tprel_lo(<var>symbol</var>)(a5) // R_RISCV_TPREL_LO12_I/S
  144. </pre></div>
  145. </dd>
  146. <dt><code>%tls_ie_pcrel_hi(<var>symbol</var>)</code></dt>
  147. <dd><p>The high 20 bits of relative address between pc and GOT entry. It is
  148. usually used with the %pcrel_lo modifier to access the thread local
  149. variable <var>symbol</var> in TLS Initial Exec.
  150. </p>
  151. <div class="smallexample">
  152. <pre class="smallexample"> la.tls.ie a5, <var>symbol</var>
  153. add a5, a5, tp
  154. load/store t0, 0(a5)
  155. </pre></div>
  156. <p>The pseudo la.tls.ie instruction can be expended to
  157. </p>
  158. <div class="smallexample">
  159. <pre class="smallexample"><var>label</var>:
  160. auipc a5, %tls_ie_pcrel_hi(<var>symbol</var>) // R_RISCV_TLS_GOT_HI20
  161. load a5, %pcrel_lo(<var>label</var>)(a5) // R_RISCV_PCREL_LO12_I
  162. </pre></div>
  163. </dd>
  164. <dt><code>%tls_gd_pcrel_hi(<var>symbol</var>)</code></dt>
  165. <dd><p>The high 20 bits of relative address between pc and GOT entry. It is
  166. usually used with the %pcrel_lo modifier to access the thread local variable
  167. <var>symbol</var> in TLS Global Dynamic.
  168. </p>
  169. <div class="smallexample">
  170. <pre class="smallexample"> la.tls.gd a0, <var>symbol</var>
  171. call __tls_get_addr@plt
  172. mv a5, a0
  173. load/store t0, 0(a5)
  174. </pre></div>
  175. <p>The pseudo la.tls.gd instruction can be expended to
  176. </p>
  177. <div class="smallexample">
  178. <pre class="smallexample"><var>label</var>:
  179. auipc a0, %tls_gd_pcrel_hi(<var>symbol</var>) // R_RISCV_TLS_GD_HI20
  180. addi a0, a0, %pcrel_lo(<var>label</var>) // R_RISCV_PCREL_LO12_I
  181. </pre></div>
  182. </dd>
  183. </dl>
  184. <hr>
  185. <div class="header">
  186. <p>
  187. Next: <a href="RISC_002dV_002dFormats.html#RISC_002dV_002dFormats" accesskey="n" rel="next">RISC-V-Formats</a>, Previous: <a href="RISC_002dV_002dDirectives.html#RISC_002dV_002dDirectives" accesskey="p" rel="prev">RISC-V-Directives</a>, Up: <a href="RISC_002dV_002dDependent.html#RISC_002dV_002dDependent" accesskey="u" rel="up">RISC-V-Dependent</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
  188. </div>
  189. </body>
  190. </html>