You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
9.8KB

  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>OpenRISC-Relocs (Using as)</title>
  16. <meta name="description" content="OpenRISC-Relocs (Using as)">
  17. <meta name="keywords" content="OpenRISC-Relocs (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="OpenRISC_002dSyntax.html#OpenRISC_002dSyntax" rel="up" title="OpenRISC-Syntax">
  25. <link href="OpenRISC_002dFloat.html#OpenRISC_002dFloat" rel="next" title="OpenRISC-Float">
  26. <link href="OpenRISC_002dRegs.html#OpenRISC_002dRegs" rel="prev" title="OpenRISC-Regs">
  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="OpenRISC_002dRelocs"></a>
  57. <div class="header">
  58. <p>
  59. Previous: <a href="OpenRISC_002dRegs.html#OpenRISC_002dRegs" accesskey="p" rel="prev">OpenRISC-Regs</a>, Up: <a href="OpenRISC_002dSyntax.html#OpenRISC_002dSyntax" accesskey="u" rel="up">OpenRISC-Syntax</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="Relocations-3"></a>
  63. <h4 class="subsubsection">9.33.1.3 Relocations</h4>
  64. <a name="index-OpenRISC-relocations"></a>
  65. <a name="index-relocations_002c-OpenRISC"></a>
  66. <p>ELF relocations are available as defined in the OpenRISC architecture
  67. specification.
  68. </p>
  69. <p><code>R_OR1K_HI_16_IN_INSN</code> is obtained using &lsquo;<samp>hi</samp>&rsquo; and
  70. <code>R_OR1K_LO_16_IN_INSN</code> and <code>R_OR1K_SLO16</code> are obtained using
  71. &lsquo;<samp>lo</samp>&rsquo;. For signed offsets <code>R_OR1K_AHI16</code> is obtained from
  72. &lsquo;<samp>ha</samp>&rsquo;. For example:
  73. </p>
  74. <div class="example">
  75. <pre class="example">l.movhi r5, hi(symbol)
  76. l.ori r5, r5, lo(symbol)
  77. l.movhi r5, ha(symbol)
  78. l.addi r5, r5, lo(symbol)
  79. </pre></div>
  80. <p>These &ldquo;high&rdquo; mnemonics extract bits 31:16 of their operand,
  81. and the &ldquo;low&rdquo; mnemonics extract bits 15:0 of their operand.
  82. </p>
  83. <p>The PC relative relocation <code>R_OR1K_GOTPC_HI16</code> can be obtained by
  84. enclosing an operand inside of &lsquo;<samp>gotpchi</samp>&rsquo;. Likewise, the
  85. <code>R_OR1K_GOTPC_LO16</code> relocation can be obtained using &lsquo;<samp>gotpclo</samp>&rsquo;.
  86. These are mostly used when assembling PIC code. For example, the
  87. standard PIC sequence on OpenRISC to get the base of the global offset
  88. table, PC relative, into a register, can be performed as:
  89. </p>
  90. <div class="example">
  91. <pre class="example">l.jal 0x8
  92. l.movhi r17, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
  93. l.ori r17, r17, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
  94. l.add r17, r17, r9
  95. </pre></div>
  96. <p>Several relocations exist to allow the link editor to perform GOT data
  97. references. The <code>R_OR1K_GOT16</code> relocation can obtained by enclosing an
  98. operand inside of &lsquo;<samp>got</samp>&rsquo;. For example, assuming the GOT base is in
  99. register <code>r17</code>.
  100. </p>
  101. <div class="example">
  102. <pre class="example">l.lwz r19, got(a)(r17)
  103. l.lwz r21, 0(r19)
  104. </pre></div>
  105. <p>Also, several relocations exist for local GOT references. The
  106. <code>R_OR1K_GOTOFF_AHI16</code> relocation can obtained by enclosing an operand
  107. inside of &lsquo;<samp>gotoffha</samp>&rsquo;. Likewise, <code>R_OR1K_GOTOFF_LO16</code> and
  108. <code>R_OR1K_GOTOFF_SLO16</code> can be obtained by enclosing an operand inside of
  109. &lsquo;<samp>gotofflo</samp>&rsquo;. For example, assuming the GOT base is in register
  110. <code>rl7</code>:
  111. </p>
  112. <div class="example">
  113. <pre class="example">l.movhi r19, gotoffha(symbol)
  114. l.add r19, r19, r17
  115. l.lwz r19, gotofflo(symbol)(r19)
  116. </pre></div>
  117. <p>The above PC relative relocations use a <code>l.jal</code> (jump) instruction
  118. and reading of the link register to load the PC. OpenRISC also supports
  119. page offset PC relative locations without a jump instruction using the
  120. <code>l.adrp</code> instruction. By default the <code>l.adrp</code> instruction will
  121. create an <code>R_OR1K_PCREL_PG21</code> relocation.
  122. Likewise, <code>BFD_RELOC_OR1K_LO13</code> and <code>BFD_RELOC_OR1K_SLO13</code> can
  123. be obtained by enclosing an operand inside of &lsquo;<samp>po</samp>&rsquo;. For example:
  124. </p>
  125. <div class="example">
  126. <pre class="example">l.adrp r3, symbol
  127. l.ori r4, r3, po(symbol)
  128. l.lbz r5, po(symbol)(r3)
  129. l.sb po(symbol)(r3), r6
  130. </pre></div>
  131. <p>Likewise the page offset relocations can be used with GOT references. The
  132. relocation <code>R_OR1K_GOT_PG21</code> can be obtained by enclosing an
  133. <code>l.adrp</code> immediate operand inside of &lsquo;<samp>got</samp>&rsquo;. Likewise,
  134. <code>R_OR1K_GOT_LO13</code> can be obtained by enclosing an operand inside of
  135. &lsquo;<samp>gotpo</samp>&rsquo;. For example to load the value of a GOT symbol into register
  136. &lsquo;<samp>r5</samp>&rsquo; we can do:
  137. </p>
  138. <div class="example">
  139. <pre class="example">l.adrp r17, got(_GLOBAL_OFFSET_TABLE_)
  140. l.lwz r5, gotpo(symbol)(r17)
  141. </pre></div>
  142. <p>There are many relocations that can be requested for access to
  143. thread local storage variables. All of the OpenRISC TLS mnemonics
  144. are supported:
  145. </p>
  146. <ul>
  147. <li> <code>R_OR1K_TLS_GD_HI16</code> is requested using &lsquo;<samp>tlsgdhi</samp>&rsquo;.
  148. </li><li> <code>R_OR1K_TLS_GD_LO16</code> is requested using &lsquo;<samp>tlsgdlo</samp>&rsquo;.
  149. </li><li> <code>R_OR1K_TLS_GD_PG21</code> is requested using &lsquo;<samp>tldgd</samp>&rsquo;.
  150. </li><li> <code>R_OR1K_TLS_GD_LO13</code> is requested using &lsquo;<samp>tlsgdpo</samp>&rsquo;.
  151. </li><li> <code>R_OR1K_TLS_LDM_HI16</code> is requested using &lsquo;<samp>tlsldmhi</samp>&rsquo;.
  152. </li><li> <code>R_OR1K_TLS_LDM_LO16</code> is requested using &lsquo;<samp>tlsldmlo</samp>&rsquo;.
  153. </li><li> <code>R_OR1K_TLS_LDM_PG21</code> is requested using &lsquo;<samp>tldldm</samp>&rsquo;.
  154. </li><li> <code>R_OR1K_TLS_LDM_LO13</code> is requested using &lsquo;<samp>tlsldmpo</samp>&rsquo;.
  155. </li><li> <code>R_OR1K_TLS_LDO_HI16</code> is requested using &lsquo;<samp>dtpoffhi</samp>&rsquo;.
  156. </li><li> <code>R_OR1K_TLS_LDO_LO16</code> is requested using &lsquo;<samp>dtpofflo</samp>&rsquo;.
  157. </li><li> <code>R_OR1K_TLS_IE_HI16</code> is requested using &lsquo;<samp>gottpoffhi</samp>&rsquo;.
  158. </li><li> <code>R_OR1K_TLS_IE_AHI16</code> is requested using &lsquo;<samp>gottpoffha</samp>&rsquo;.
  159. </li><li> <code>R_OR1K_TLS_IE_LO16</code> is requested using &lsquo;<samp>gottpofflo</samp>&rsquo;.
  160. </li><li> <code>R_OR1K_TLS_IE_PG21</code> is requested using &lsquo;<samp>gottp</samp>&rsquo;.
  161. </li><li> <code>R_OR1K_TLS_IE_LO13</code> is requested using &lsquo;<samp>gottppo</samp>&rsquo;.
  162. </li><li> <code>R_OR1K_TLS_LE_HI16</code> is requested using &lsquo;<samp>tpoffhi</samp>&rsquo;.
  163. </li><li> <code>R_OR1K_TLS_LE_AHI16</code> is requested using &lsquo;<samp>tpoffha</samp>&rsquo;.
  164. </li><li> <code>R_OR1K_TLS_LE_LO16</code> is requested using &lsquo;<samp>tpofflo</samp>&rsquo;.
  165. </li><li> <code>R_OR1K_TLS_LE_SLO16</code> also is requested using &lsquo;<samp>tpofflo</samp>&rsquo;
  166. depending on the instruction format.
  167. </li></ul>
  168. <p>Here are some example TLS model sequences.
  169. </p>
  170. <p>First, General Dynamic:
  171. </p>
  172. <div class="example">
  173. <pre class="example">l.movhi r17, tlsgdhi(symbol)
  174. l.ori r17, r17, tlsgdlo(symbol)
  175. l.add r17, r17, r16
  176. l.or r3, r17, r17
  177. l.jal plt(__tls_get_addr)
  178. l.nop
  179. </pre></div>
  180. <p>Initial Exec:
  181. </p>
  182. <div class="example">
  183. <pre class="example">l.movhi r17, gottpoffhi(symbol)
  184. l.add r17, r17, r16
  185. l.lwz r17, gottpofflo(symbol)(r17)
  186. l.add r17, r17, r10
  187. l.lbs r17, 0(r17)
  188. </pre></div>
  189. <p>And finally, Local Exec:
  190. </p>
  191. <div class="example">
  192. <pre class="example">l.movhi r17, tpoffha(symbol)
  193. l.add r17, r17, r10
  194. l.addi r17, r17, tpofflo(symbol)
  195. l.lbs r17, 0(r17)
  196. </pre></div>
  197. <hr>
  198. <div class="header">
  199. <p>
  200. Previous: <a href="OpenRISC_002dRegs.html#OpenRISC_002dRegs" accesskey="p" rel="prev">OpenRISC-Regs</a>, Up: <a href="OpenRISC_002dSyntax.html#OpenRISC_002dSyntax" accesskey="u" rel="up">OpenRISC-Syntax</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>
  201. </div>
  202. </body>
  203. </html>