MIPS-Small-Data.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>Using as: MIPS Small Data</title>
  15. <meta name="description" content="Using as: MIPS Small Data">
  16. <meta name="keywords" content="Using as: MIPS Small Data">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="MIPS_002dDependent.html#MIPS_002dDependent" rel="up" title="MIPS-Dependent">
  25. <link href="MIPS-ISA.html#MIPS-ISA" rel="next" title="MIPS ISA">
  26. <link href="MIPS-Symbol-Sizes.html#MIPS-Symbol-Sizes" rel="prev" title="MIPS Symbol Sizes">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.smallquotation {font-size: smaller}
  31. div.display {margin-left: 3.2em}
  32. div.example {margin-left: 3.2em}
  33. div.indentedblock {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  49. span.nolinebreak {white-space:nowrap}
  50. span.roman {font-family:serif; font-weight:normal}
  51. span.sansserif {font-family:sans-serif; font-weight:normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  57. <a name="MIPS-Small-Data"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="MIPS-ISA.html#MIPS-ISA" accesskey="n" rel="next">MIPS ISA</a>, Previous: <a href="MIPS-Symbol-Sizes.html#MIPS-Symbol-Sizes" accesskey="p" rel="prev">MIPS Symbol Sizes</a>, Up: <a href="MIPS_002dDependent.html#MIPS_002dDependent" accesskey="u" rel="up">MIPS-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>
  61. </div>
  62. <hr>
  63. <a name="Controlling-the-use-of-small-data-accesses"></a>
  64. <h4 class="subsection">9.27.4 Controlling the use of small data accesses</h4>
  65. <a name="index-small-data_002c-MIPS"></a>
  66. <a name="index-gp-register_002c-MIPS"></a>
  67. <p>It often takes several instructions to load the address of a symbol.
  68. For example, when &lsquo;<samp>addr</samp>&rsquo; is a 32-bit symbol, the non-PIC expansion
  69. of &lsquo;<samp>dla $4,addr</samp>&rsquo; is usually:
  70. </p>
  71. <div class="smallexample">
  72. <pre class="smallexample">lui $4,%hi(addr)
  73. daddiu $4,$4,%lo(addr)
  74. </pre></div>
  75. <p>The sequence is much longer when &lsquo;<samp>addr</samp>&rsquo; is a 64-bit symbol.
  76. See <a href="MIPS-Symbol-Sizes.html#MIPS-Symbol-Sizes">Directives to override the size of symbols</a>.
  77. </p>
  78. <p>In order to cut down on this overhead, most embedded MIPS systems
  79. set aside a 64-kilobyte &ldquo;small data&rdquo; area and guarantee that all
  80. data of size <var>n</var> and smaller will be placed in that area.
  81. The limit <var>n</var> is passed to both the assembler and the linker
  82. using the command-line option <samp>-G <var>n</var></samp>, see <a href="MIPS-Options.html#MIPS-Options">Assembler options</a>. Note that the same value of <var>n</var> must be used
  83. when linking and when assembling all input files to the link; any
  84. inconsistency could cause a relocation overflow error.
  85. </p>
  86. <p>The size of an object in the <code>.bss</code> section is set by the
  87. <code>.comm</code> or <code>.lcomm</code> directive that defines it. The size of
  88. an external object may be set with the <code>.extern</code> directive. For
  89. example, &lsquo;<samp>.extern sym,4</samp>&rsquo; declares that the object at <code>sym</code>
  90. is 4 bytes in length, while leaving <code>sym</code> otherwise undefined.
  91. </p>
  92. <p>When no <samp>-G</samp> option is given, the default limit is 8 bytes.
  93. The option <samp>-G 0</samp> prevents any data from being automatically
  94. classified as small.
  95. </p>
  96. <p>It is also possible to mark specific objects as small by putting them
  97. in the special sections <code>.sdata</code> and <code>.sbss</code>, which are
  98. &ldquo;small&rdquo; counterparts of <code>.data</code> and <code>.bss</code> respectively.
  99. The toolchain will treat such data as small regardless of the
  100. <samp>-G</samp> setting.
  101. </p>
  102. <p>On startup, systems that support a small data area are expected to
  103. initialize register <code>$28</code>, also known as <code>$gp</code>, in such a
  104. way that small data can be accessed using a 16-bit offset from that
  105. register. For example, when &lsquo;<samp>addr</samp>&rsquo; is small data,
  106. the &lsquo;<samp>dla $4,addr</samp>&rsquo; instruction above is equivalent to:
  107. </p>
  108. <div class="smallexample">
  109. <pre class="smallexample">daddiu $4,$28,%gp_rel(addr)
  110. </pre></div>
  111. <p>Small data is not supported for SVR4-style PIC.
  112. </p>
  113. <hr>
  114. <div class="header">
  115. <p>
  116. Next: <a href="MIPS-ISA.html#MIPS-ISA" accesskey="n" rel="next">MIPS ISA</a>, Previous: <a href="MIPS-Symbol-Sizes.html#MIPS-Symbol-Sizes" accesskey="p" rel="prev">MIPS Symbol Sizes</a>, Up: <a href="MIPS_002dDependent.html#MIPS_002dDependent" accesskey="u" rel="up">MIPS-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>
  117. </div>
  118. </body>
  119. </html>