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.

234 lines
9.3KB

  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 linker LD
  4. (GNU Arm Embedded Toolchain 10-2020-q4-major)
  5. version 2.35.1.
  6. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  7. Permission is granted to copy, distribute and/or modify this document
  8. under the terms of the GNU Free Documentation License, Version 1.3
  9. or any later version published by the Free Software Foundation;
  10. with no Invariant Sections, with no Front-Cover Texts, and with no
  11. Back-Cover Texts. A copy of the license is included in the
  12. section entitled "GNU Free Documentation License". -->
  13. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>REGION_ALIAS (LD)</title>
  17. <meta name="description" content="REGION_ALIAS (LD)">
  18. <meta name="keywords" content="REGION_ALIAS (LD)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Simple-Commands.html#Simple-Commands" rel="up" title="Simple Commands">
  26. <link href="Miscellaneous-Commands.html#Miscellaneous-Commands" rel="next" title="Miscellaneous Commands">
  27. <link href="Format-Commands.html#Format-Commands" rel="prev" title="Format Commands">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style: oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; 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">
  57. <a name="REGION_005fALIAS"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Miscellaneous-Commands.html#Miscellaneous-Commands" accesskey="n" rel="next">Miscellaneous Commands</a>, Previous: <a href="Format-Commands.html#Format-Commands" accesskey="p" rel="prev">Format Commands</a>, Up: <a href="Simple-Commands.html#Simple-Commands" accesskey="u" rel="up">Simple Commands</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <a name="Assign-alias-names-to-memory-regions"></a>
  64. <h4 class="subsection">3.4.4 Assign alias names to memory regions</h4>
  65. <a name="index-REGION_005fALIAS_0028alias_002c-region_0029"></a>
  66. <a name="index-region-alias"></a>
  67. <a name="index-region-names"></a>
  68. <p>Alias names can be added to existing memory regions created with the
  69. <a href="MEMORY.html#MEMORY">MEMORY</a> command. Each name corresponds to at most one memory region.
  70. </p>
  71. <div class="smallexample">
  72. <pre class="smallexample">REGION_ALIAS(<var>alias</var>, <var>region</var>)
  73. </pre></div>
  74. <p>The <code>REGION_ALIAS</code> function creates an alias name <var>alias</var> for the
  75. memory region <var>region</var>. This allows a flexible mapping of output sections
  76. to memory regions. An example follows.
  77. </p>
  78. <p>Suppose we have an application for embedded systems which come with various
  79. memory storage devices. All have a general purpose, volatile memory <code>RAM</code>
  80. that allows code execution or data storage. Some may have a read-only,
  81. non-volatile memory <code>ROM</code> that allows code execution and read-only data
  82. access. The last variant is a read-only, non-volatile memory <code>ROM2</code> with
  83. read-only data access and no code execution capability. We have four output
  84. sections:
  85. </p>
  86. <ul>
  87. <li> <code>.text</code> program code;
  88. </li><li> <code>.rodata</code> read-only data;
  89. </li><li> <code>.data</code> read-write initialized data;
  90. </li><li> <code>.bss</code> read-write zero initialized data.
  91. </li></ul>
  92. <p>The goal is to provide a linker command file that contains a system independent
  93. part defining the output sections and a system dependent part mapping the
  94. output sections to the memory regions available on the system. Our embedded
  95. systems come with three different memory setups <code>A</code>, <code>B</code> and
  96. <code>C</code>:
  97. </p><table>
  98. <tr><td width="25%">Section</td><td width="25%">Variant A</td><td width="25%">Variant B</td><td width="25%">Variant C</td></tr>
  99. <tr><td width="25%">.text</td><td width="25%">RAM</td><td width="25%">ROM</td><td width="25%">ROM</td></tr>
  100. <tr><td width="25%">.rodata</td><td width="25%">RAM</td><td width="25%">ROM</td><td width="25%">ROM2</td></tr>
  101. <tr><td width="25%">.data</td><td width="25%">RAM</td><td width="25%">RAM/ROM</td><td width="25%">RAM/ROM2</td></tr>
  102. <tr><td width="25%">.bss</td><td width="25%">RAM</td><td width="25%">RAM</td><td width="25%">RAM</td></tr>
  103. </table>
  104. <p>The notation <code>RAM/ROM</code> or <code>RAM/ROM2</code> means that this section is
  105. loaded into region <code>ROM</code> or <code>ROM2</code> respectively. Please note that
  106. the load address of the <code>.data</code> section starts in all three variants at
  107. the end of the <code>.rodata</code> section.
  108. </p>
  109. <p>The base linker script that deals with the output sections follows. It
  110. includes the system dependent <code>linkcmds.memory</code> file that describes the
  111. memory layout:
  112. </p><div class="smallexample">
  113. <pre class="smallexample">INCLUDE linkcmds.memory
  114. SECTIONS
  115. {
  116. .text :
  117. {
  118. *(.text)
  119. } &gt; REGION_TEXT
  120. .rodata :
  121. {
  122. *(.rodata)
  123. rodata_end = .;
  124. } &gt; REGION_RODATA
  125. .data : AT (rodata_end)
  126. {
  127. data_start = .;
  128. *(.data)
  129. } &gt; REGION_DATA
  130. data_size = SIZEOF(.data);
  131. data_load_start = LOADADDR(.data);
  132. .bss :
  133. {
  134. *(.bss)
  135. } &gt; REGION_BSS
  136. }
  137. </pre></div>
  138. <p>Now we need three different <code>linkcmds.memory</code> files to define memory
  139. regions and alias names. The content of <code>linkcmds.memory</code> for the three
  140. variants <code>A</code>, <code>B</code> and <code>C</code>:
  141. </p><dl compact="compact">
  142. <dt><code>A</code></dt>
  143. <dd><p>Here everything goes into the <code>RAM</code>.
  144. </p><div class="smallexample">
  145. <pre class="smallexample">MEMORY
  146. {
  147. RAM : ORIGIN = 0, LENGTH = 4M
  148. }
  149. REGION_ALIAS(&quot;REGION_TEXT&quot;, RAM);
  150. REGION_ALIAS(&quot;REGION_RODATA&quot;, RAM);
  151. REGION_ALIAS(&quot;REGION_DATA&quot;, RAM);
  152. REGION_ALIAS(&quot;REGION_BSS&quot;, RAM);
  153. </pre></div>
  154. </dd>
  155. <dt><code>B</code></dt>
  156. <dd><p>Program code and read-only data go into the <code>ROM</code>. Read-write data goes
  157. into the <code>RAM</code>. An image of the initialized data is loaded into the
  158. <code>ROM</code> and will be copied during system start into the <code>RAM</code>.
  159. </p><div class="smallexample">
  160. <pre class="smallexample">MEMORY
  161. {
  162. ROM : ORIGIN = 0, LENGTH = 3M
  163. RAM : ORIGIN = 0x10000000, LENGTH = 1M
  164. }
  165. REGION_ALIAS(&quot;REGION_TEXT&quot;, ROM);
  166. REGION_ALIAS(&quot;REGION_RODATA&quot;, ROM);
  167. REGION_ALIAS(&quot;REGION_DATA&quot;, RAM);
  168. REGION_ALIAS(&quot;REGION_BSS&quot;, RAM);
  169. </pre></div>
  170. </dd>
  171. <dt><code>C</code></dt>
  172. <dd><p>Program code goes into the <code>ROM</code>. Read-only data goes into the
  173. <code>ROM2</code>. Read-write data goes into the <code>RAM</code>. An image of the
  174. initialized data is loaded into the <code>ROM2</code> and will be copied during
  175. system start into the <code>RAM</code>.
  176. </p><div class="smallexample">
  177. <pre class="smallexample">MEMORY
  178. {
  179. ROM : ORIGIN = 0, LENGTH = 2M
  180. ROM2 : ORIGIN = 0x10000000, LENGTH = 1M
  181. RAM : ORIGIN = 0x20000000, LENGTH = 1M
  182. }
  183. REGION_ALIAS(&quot;REGION_TEXT&quot;, ROM);
  184. REGION_ALIAS(&quot;REGION_RODATA&quot;, ROM2);
  185. REGION_ALIAS(&quot;REGION_DATA&quot;, RAM);
  186. REGION_ALIAS(&quot;REGION_BSS&quot;, RAM);
  187. </pre></div>
  188. </dd>
  189. </dl>
  190. <p>It is possible to write a common system initialization routine to copy the
  191. <code>.data</code> section from <code>ROM</code> or <code>ROM2</code> into the <code>RAM</code> if
  192. necessary:
  193. </p><div class="smallexample">
  194. <pre class="smallexample">#include &lt;string.h&gt;
  195. extern char data_start [];
  196. extern char data_size [];
  197. extern char data_load_start [];
  198. void copy_data(void)
  199. {
  200. if (data_start != data_load_start)
  201. {
  202. memcpy(data_start, data_load_start, (size_t) data_size);
  203. }
  204. }
  205. </pre></div>
  206. <hr>
  207. <div class="header">
  208. <p>
  209. Next: <a href="Miscellaneous-Commands.html#Miscellaneous-Commands" accesskey="n" rel="next">Miscellaneous Commands</a>, Previous: <a href="Format-Commands.html#Format-Commands" accesskey="p" rel="prev">Format Commands</a>, Up: <a href="Simple-Commands.html#Simple-Commands" accesskey="u" rel="up">Simple Commands</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  210. </div>
  211. </body>
  212. </html>