gcc_m4_mps3.ld 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Copyright (c) 2023 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /* ----------------------------------------------------------------------------
  19. Stack seal size definition
  20. *----------------------------------------------------------------------------*/
  21. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  22. #define __STACKSEAL_SIZE ( 8 )
  23. #else
  24. #define __STACKSEAL_SIZE ( 0 )
  25. #endif
  26. /* ----------------------------------------------------------------------------
  27. Memory definition
  28. *----------------------------------------------------------------------------*/
  29. MEMORY
  30. {
  31. ROM0 (rx) : ORIGIN = __ROM0_BASE, LENGTH = __ROM0_SIZE
  32. #if __ROM1_SIZE > 0
  33. ROM1 (rx) : ORIGIN = __ROM1_BASE, LENGTH = __ROM1_SIZE
  34. #endif
  35. #if __ROM2_SIZE > 0
  36. ROM2 (rx) : ORIGIN = __ROM2_BASE, LENGTH = __ROM2_SIZE
  37. #endif
  38. #if __ROM3_SIZE > 0
  39. ROM3 (rx) : ORIGIN = __ROM3_BASE, LENGTH = __ROM3_SIZE
  40. #endif
  41. RAM0 (rwx) : ORIGIN = __RAM0_BASE, LENGTH = __RAM0_SIZE
  42. #if __RAM1_SIZE > 0
  43. RAM1 (rwx) : ORIGIN = __RAM1_BASE, LENGTH = __RAM1_SIZE
  44. #endif
  45. #if __RAM2_SIZE > 0
  46. RAM2 (rwx) : ORIGIN = __RAM2_BASE, LENGTH = __RAM2_SIZE
  47. #endif
  48. #if __RAM3_SIZE > 0
  49. RAM3 (rwx) : ORIGIN = __RAM3_BASE, LENGTH = __RAM3_SIZE
  50. #endif
  51. }
  52. /* Linker script to place sections and symbol values. Should be used together
  53. * with other linker script that defines memory regions FLASH and RAM.
  54. * It references following symbols, which must be defined in code:
  55. * Reset_Handler : Entry of reset handler
  56. *
  57. * It defines following symbols, which code can use without definition:
  58. * __exidx_start
  59. * __exidx_end
  60. * __copy_table_start__
  61. * __copy_table_end__
  62. * __zero_table_start__
  63. * __zero_table_end__
  64. * __etext (deprecated)
  65. * __data_start__
  66. * __preinit_array_start
  67. * __preinit_array_end
  68. * __init_array_start
  69. * __init_array_end
  70. * __fini_array_start
  71. * __fini_array_end
  72. * __data_end__
  73. * __bss_start__
  74. * __bss_end__
  75. * __end__
  76. * end
  77. * __HeapLimit
  78. * __StackLimit
  79. * __StackTop
  80. * __stack
  81. */
  82. ENTRY(Reset_Handler)
  83. SECTIONS
  84. {
  85. .text :
  86. {
  87. KEEP(*(.vectors))
  88. *(.text*)
  89. KEEP(*(.init))
  90. KEEP(*(.fini))
  91. /* .ctors */
  92. *crtbegin.o(.ctors)
  93. *crtbegin?.o(.ctors)
  94. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  95. *(SORT(.ctors.*))
  96. *(.ctors)
  97. /* .dtors */
  98. *crtbegin.o(.dtors)
  99. *crtbegin?.o(.dtors)
  100. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  101. *(SORT(.dtors.*))
  102. *(.dtors)
  103. *(.rodata*)
  104. KEEP(*(.eh_frame*))
  105. } > ROM0
  106. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  107. .gnu.sgstubs :
  108. {
  109. . = ALIGN(32);
  110. } > ROM0
  111. #endif
  112. .ARM.extab :
  113. {
  114. *(.ARM.extab* .gnu.linkonce.armextab.*)
  115. } > ROM0
  116. __exidx_start = .;
  117. .ARM.exidx :
  118. {
  119. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  120. } > ROM0
  121. __exidx_end = .;
  122. .copy.table :
  123. {
  124. . = ALIGN(4);
  125. __copy_table_start__ = .;
  126. LONG (LOADADDR(.data))
  127. LONG (ADDR(.data))
  128. LONG (SIZEOF(.data) / 4)
  129. /* Add each additional data section here */
  130. /*
  131. LONG (LOADADDR(.data2))
  132. LONG (ADDR(.data2))
  133. LONG (SIZEOF(.data2) / 4)
  134. */
  135. __copy_table_end__ = .;
  136. } > ROM0
  137. .zero.table :
  138. {
  139. . = ALIGN(4);
  140. __zero_table_start__ = .;
  141. /* .bss initialization to zero is already done during C Run-Time Startup.
  142. LONG (ADDR(.bss))
  143. LONG (SIZEOF(.bss) / 4)
  144. */
  145. /* Add each additional bss section here */
  146. /*
  147. LONG (ADDR(.bss2))
  148. LONG (SIZEOF(.bss2) / 4)
  149. */
  150. __zero_table_end__ = .;
  151. } > ROM0
  152. /*
  153. * This __etext variable is kept for backward compatibility with older,
  154. * ASM based startup files.
  155. */
  156. PROVIDE(__etext = LOADADDR(.data));
  157. .data : ALIGN(4)
  158. {
  159. __data_start__ = .;
  160. *(vtable)
  161. *(.data)
  162. *(.data.*)
  163. . = ALIGN(4);
  164. /* preinit data */
  165. PROVIDE_HIDDEN (__preinit_array_start = .);
  166. KEEP(*(.preinit_array))
  167. PROVIDE_HIDDEN (__preinit_array_end = .);
  168. . = ALIGN(4);
  169. /* init data */
  170. PROVIDE_HIDDEN (__init_array_start = .);
  171. KEEP(*(SORT(.init_array.*)))
  172. KEEP(*(.init_array))
  173. PROVIDE_HIDDEN (__init_array_end = .);
  174. . = ALIGN(4);
  175. /* finit data */
  176. PROVIDE_HIDDEN (__fini_array_start = .);
  177. KEEP(*(SORT(.fini_array.*)))
  178. KEEP(*(.fini_array))
  179. PROVIDE_HIDDEN (__fini_array_end = .);
  180. KEEP(*(.jcr*))
  181. . = ALIGN(4);
  182. /* All data end */
  183. __data_end__ = .;
  184. } > RAM0 AT > ROM0
  185. /*
  186. * Secondary data section, optional
  187. *
  188. * Remember to add each additional data section
  189. * to the .copy.table above to assure proper
  190. * initialization during startup.
  191. */
  192. /*
  193. .data2 : ALIGN(4)
  194. {
  195. . = ALIGN(4);
  196. __data2_start__ = .;
  197. *(.data2)
  198. *(.data2.*)
  199. . = ALIGN(4);
  200. __data2_end__ = .;
  201. } > RAM1 AT > ROM0
  202. */
  203. .bss :
  204. {
  205. . = ALIGN(4);
  206. __bss_start__ = .;
  207. *(.bss)
  208. *(.bss.*)
  209. *(COMMON)
  210. . = ALIGN(4);
  211. __bss_end__ = .;
  212. } > RAM0 AT > RAM0
  213. /*
  214. * Secondary bss section, optional
  215. *
  216. * Remember to add each additional bss section
  217. * to the .zero.table above to assure proper
  218. * initialization during startup.
  219. */
  220. /*
  221. .bss2 :
  222. {
  223. . = ALIGN(4);
  224. __bss2_start__ = .;
  225. *(.bss2)
  226. *(.bss2.*)
  227. . = ALIGN(4);
  228. __bss2_end__ = .;
  229. } > RAM1 AT > RAM1
  230. */
  231. .heap (NOLOAD) :
  232. {
  233. . = ALIGN(8);
  234. __end__ = .;
  235. PROVIDE(end = .);
  236. . = . + __HEAP_SIZE;
  237. . = ALIGN(8);
  238. __HeapLimit = .;
  239. } > RAM0
  240. .stack (ORIGIN(RAM0) + LENGTH(RAM0) - __STACK_SIZE - __STACKSEAL_SIZE) (NOLOAD) :
  241. {
  242. . = ALIGN(8);
  243. __StackLimit = .;
  244. . = . + __STACK_SIZE;
  245. . = ALIGN(8);
  246. __StackTop = .;
  247. } > RAM0
  248. PROVIDE(__stack = __StackTop);
  249. #if __STACKSEAL_SIZE > 0
  250. .stackseal (ORIGIN(RAM0) + LENGTH(RAM0) - __STACKSEAL_SIZE) (NOLOAD) :
  251. {
  252. . = ALIGN(8);
  253. __StackSeal = .;
  254. . = . + 8;
  255. . = ALIGN(8);
  256. } > RAM0
  257. #endif
  258. /* Check if data + heap + stack exceeds RAM limit */
  259. ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
  260. }