sections.ld 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /*
  2. * To make use of the multi-region initialisations, define
  3. * OS_INCLUDE_STARTUP_INIT_MULTIPLE_RAM_SECTIONS for the _startup.c file.
  4. */
  5. _Flash_Total = LENGTH(FLASH);
  6. _Flash_Used = SIZEOF(.flashtext)+SIZEOF(.ARM.extab)+SIZEOF(.ARM.exidx);
  7. _Ram_Total = LENGTH(RAM);
  8. _Ram_Text = SIZEOF(.isr_vector)+SIZEOF(.text)+SIZEOF(.inits);
  9. _Ram_Data = SIZEOF(.data);
  10. _Ram_Bss = SIZEOF(.bss);
  11. /* Used for Alert*/
  12. FLASH_LIMIT = _Flash_Total;
  13. /*
  14. * The '__stack' definition is required by crt0, do not remove it.
  15. */
  16. __stack = ORIGIN(RAM) + LENGTH(RAM);
  17. /*
  18. * Default stack sizes.
  19. * These are used by the startup in order to allocate stacks
  20. * for the different modes.
  21. */
  22. __Main_Stack_Size = 0x400 ;
  23. PROVIDE ( _Main_Stack_Size = __Main_Stack_Size ) ;
  24. __Main_Stack_Limit = __stack - __Main_Stack_Size ;
  25. /* "PROVIDE" allows to easily override these values from an
  26. * object file or the command line. */
  27. PROVIDE ( _Main_Stack_Limit = __Main_Stack_Limit ) ;
  28. /*
  29. * There will be a link error if there is not this amount of
  30. * RAM free at the end.
  31. */
  32. _Minimum_Stack_Size = __Main_Stack_Size ;
  33. /*
  34. * Default heap definitions.
  35. * The heap start immediately after the last statically allocated
  36. * .sbss/.noinit section, and extends up to the main stack limit.
  37. */
  38. PROVIDE ( _Heap_Begin = _end_noinit ) ;
  39. PROVIDE ( _Heap_Limit = __stack - __Main_Stack_Size ) ;
  40. /*
  41. * the RAM area's size is 0xE000, stack use __Main_Stack_Size,
  42. * the others is heap size
  43. */
  44. __Heap_Size = _Heap_Limit - _Heap_Begin ;
  45. _Minimum_Heap_Size = __Heap_Size ;
  46. /*
  47. __malloc_sbrk_base = _Heap_Begin ;
  48. __malloc_trim_threshold = __Heap_Size ;
  49. */
  50. /*
  51. * The entry point is informative, for debuggers and simulators,
  52. * since the Cortex-M vector points to it anyway.
  53. */
  54. ENTRY(Reset_Handler)
  55. /* Sections Definitions */
  56. SECTIONS
  57. {
  58. /*
  59. * For some STRx devices, the beginning of the startup code
  60. * is stored in the .flashtext section, which goes to FLASH.
  61. */
  62. .flashtext : ALIGN(4)
  63. {
  64. *.o.flash(.text .text.*) /* all code in ram */
  65. *(.flashtext .flashtext.*) /* attribute used */
  66. *.o.flash(.rodata .rodata.* .constdata .constdata.*) /* read only or const data */
  67. . = ALIGN(4);
  68. __fsymtab_start = .;
  69. KEEP(*(FSymTab))
  70. __fsymtab_end = .;
  71. /* section information for initial. */
  72. . = ALIGN(4);
  73. __zos_init_start = .;
  74. KEEP(*(SORT(.zos_init_call*)))
  75. __zos_init_end = .;
  76. . = ALIGN(4);
  77. } >FLASH
  78. /*
  79. * For Cortex-M devices, the beginning of the startup code is stored in
  80. * the .isr_vector section, which goes to RAM.
  81. */
  82. .isr_vector : ALIGN(4)
  83. {
  84. FILL(0xFF)
  85. __vectors_start = ABSOLUTE(.) ;
  86. KEEP(*(.isr_vector)) /* Interrupt vectors */
  87. KEEP(*(.cfmconfig)) /* Freescale configuration words */
  88. /*
  89. * This section is here for convenience, to store the
  90. * startup code at the beginning of the flash area, hoping that
  91. * this will increase the readability of the listing.
  92. */
  93. *(.after_vectors .after_vectors.*) /* Startup code and ISR */
  94. } >RAM
  95. /*
  96. * The program code is stored in the .text section,
  97. * which goes to RAM.
  98. */
  99. .text : ALIGN(4)
  100. {
  101. *(.text .text.*) /* all remaining code in ram */
  102. *(.ramtext*) /* attribute used */
  103. *(.rodata .rodata.* .constdata .constdata.*) /* read only or const data */
  104. *(vtable) /* C++ virtual tables */
  105. KEEP(*(.eh_frame*))
  106. /*
  107. * Stub sections generated by the linker, to glue together
  108. * ARM and Thumb code. .glue_7 is used for ARM code calling
  109. * Thumb code, and .glue_7t is used for Thumb code calling
  110. * ARM code. Apparently always generated by the linker, for some
  111. * architectures, so better leave them here.
  112. */
  113. *(.glue_7)
  114. *(.glue_7t)
  115. } >RAM
  116. .inits : ALIGN(4)
  117. {
  118. /*
  119. * Memory regions initialisation arrays.
  120. *
  121. * Thee are two kinds of arrays for each RAM region, one for
  122. * data and one for bss. Each is iterrated at startup and the
  123. * region initialisation is performed.
  124. *
  125. * The data array includes:
  126. * - from (LOADADDR())
  127. * - region_begin (ADDR())
  128. * - region_end (ADDR()+SIZEOF())
  129. *
  130. * The bss array includes:
  131. * - region_begin (ADDR())
  132. * - region_end (ADDR()+SIZEOF())
  133. *
  134. * WARNING: It is mandatory that the regions are word aligned,
  135. * since the initialisation code works only on words.
  136. */
  137. __data_regions_array_start = .;
  138. LONG(LOADADDR(.data));
  139. LONG(ADDR(.data));
  140. LONG(ADDR(.data)+SIZEOF(.data));
  141. __data_regions_array_end = .;
  142. __bss_regions_array_start = .;
  143. LONG(ADDR(.bss));
  144. LONG(ADDR(.bss)+SIZEOF(.bss));
  145. __bss_regions_array_end = .;
  146. /* End of memory regions initialisation arrays. */
  147. /*
  148. * These are the old initialisation sections, intended to contain
  149. * naked code, with the prologue/epilogue added by crti.o/crtn.o
  150. * when linking with startup files. The standalone startup code
  151. * currently does not run these, better use the init arrays below.
  152. */
  153. KEEP(*(.init))
  154. KEEP(*(.fini))
  155. . = ALIGN(4);
  156. /*
  157. * The preinit code, i.e. an array of pointers to initialisation
  158. * functions to be performed before constructors.
  159. */
  160. PROVIDE_HIDDEN (__preinit_array_start = .);
  161. /*
  162. * Used to run the SystemInit() before anything else.
  163. */
  164. KEEP(*(.preinit_array_sysinit .preinit_array_sysinit.*))
  165. /*
  166. * Used for other platform inits.
  167. */
  168. KEEP(*(.preinit_array_platform .preinit_array_platform.*))
  169. /*
  170. * The application inits. If you need to enforce some order in
  171. * execution, create new sections, as before.
  172. */
  173. KEEP(*(.preinit_array .preinit_array.*))
  174. PROVIDE_HIDDEN (__preinit_array_end = .);
  175. . = ALIGN(4);
  176. /*
  177. * The init code, i.e. an array of pointers to static constructors.
  178. */
  179. PROVIDE_HIDDEN (__init_array_start = .);
  180. KEEP(*(SORT(.init_array.*)))
  181. KEEP(*(.init_array))
  182. PROVIDE_HIDDEN (__init_array_end = .);
  183. . = ALIGN(4);
  184. /*
  185. * The fini code, i.e. an array of pointers to static destructors.
  186. */
  187. PROVIDE_HIDDEN (__fini_array_start = .);
  188. KEEP(*(SORT(.fini_array.*)))
  189. KEEP(*(.fini_array))
  190. PROVIDE_HIDDEN (__fini_array_end = .);
  191. } >RAM
  192. /* ARM magic sections */
  193. .ARM.extab : ALIGN(4)
  194. {
  195. *(.ARM.extab* .gnu.linkonce.armextab.*)
  196. } > FLASH
  197. . = ALIGN(4);
  198. __exidx_start = .;
  199. .ARM.exidx : ALIGN(4)
  200. {
  201. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  202. } > FLASH
  203. __exidx_end = .;
  204. . = ALIGN(4);
  205. _etext = .;
  206. __etext = .;
  207. /*
  208. * This address is used by the startup code to
  209. * initialise the .data section.
  210. */
  211. _sidata = LOADADDR(.data);
  212. /*
  213. * The initialised data section.
  214. *
  215. * The program executes knowing that the data is in the RAM
  216. * but the loader puts the initial values in the FLASH (inidata).
  217. * It is one task of the startup to copy the initial values from
  218. * FLASH to RAM.
  219. */
  220. .data : ALIGN(4)
  221. {
  222. FILL(0xFF)
  223. /* This is used by the startup code to initialise the .data section */
  224. __data_start__ = . ;
  225. *(.data_begin .data_begin.*)
  226. *(.data .data.*)
  227. *(.data_end .data_end.*)
  228. . = ALIGN(4);
  229. /* This is used by the startup code to initialise the .data section */
  230. __data_end__ = . ;
  231. } >RAM
  232. /* The primary uninitialised data section. */
  233. .bss (NOLOAD) : ALIGN(4)
  234. {
  235. __bss_start__ = .; /* standard newlib definition */
  236. *(.bss_begin .bss_begin.*)
  237. *(.bss .bss.*)
  238. *(COMMON)
  239. *(.bss_end .bss_end.*)
  240. . = ALIGN(4);
  241. __bss_end__ = .; /* standard newlib definition */
  242. } >RAM
  243. .noinit (NOLOAD) : ALIGN(4)
  244. {
  245. _noinit = .;
  246. *(.noinit .noinit.*)
  247. . = ALIGN(4) ;
  248. _end_noinit = .;
  249. } > RAM
  250. /* Mandatory to be word aligned, _sbrk assumes this */
  251. PROVIDE ( end = _end_noinit ); /* was _ebss */
  252. PROVIDE ( _end = _end_noinit );
  253. PROVIDE ( __end = _end_noinit );
  254. PROVIDE ( __end__ = _end_noinit );
  255. /*
  256. * Used for validation only, do not allocate anything here!
  257. *
  258. * This is just to check that there is enough RAM left for the Main
  259. * stack. It should generate an error if it's full.
  260. */
  261. .heap : ALIGN(4)
  262. {
  263. __heap_start__ = .; /* heap start */
  264. *(.heap .heap.*)
  265. . = ALIGN(4);
  266. __heap_end__ = .; /* heap end */
  267. } >RAM
  268. ._check_stack : ALIGN(4)
  269. {
  270. . = . + _Minimum_Stack_Size ;
  271. } >RAM
  272. /* Check if sram + flash exceeds Flash Total limit */
  273. ASSERT( _Flash_Used + _Ram_Text + _Ram_Data < FLASH_LIMIT, "flash used size exceeds flash total size")
  274. /* After that there are only debugging sections. */
  275. /* This can remove the debugging information from the standard libraries */
  276. /*
  277. DISCARD :
  278. {
  279. libc.a ( * )
  280. libm.a ( * )
  281. libgcc.a ( * )
  282. }
  283. */
  284. /* Stabs debugging sections. */
  285. .stab 0 : { *(.stab) }
  286. .stabstr 0 : { *(.stabstr) }
  287. .stab.excl 0 : { *(.stab.excl) }
  288. .stab.exclstr 0 : { *(.stab.exclstr) }
  289. .stab.index 0 : { *(.stab.index) }
  290. .stab.indexstr 0 : { *(.stab.indexstr) }
  291. .comment 0 : { *(.comment) }
  292. /*
  293. * DWARF debug sections.
  294. * Symbols in the DWARF debugging sections are relative to the beginning
  295. * of the section so we begin them at 0.
  296. */
  297. /* DWARF 1 */
  298. .debug 0 : { *(.debug) }
  299. .line 0 : { *(.line) }
  300. /* GNU DWARF 1 extensions */
  301. .debug_srcinfo 0 : { *(.debug_srcinfo) }
  302. .debug_sfnames 0 : { *(.debug_sfnames) }
  303. /* DWARF 1.1 and DWARF 2 */
  304. .debug_aranges 0 : { *(.debug_aranges) }
  305. .debug_pubnames 0 : { *(.debug_pubnames) }
  306. /* DWARF 2 */
  307. .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
  308. .debug_abbrev 0 : { *(.debug_abbrev) }
  309. .debug_line 0 : { *(.debug_line) }
  310. .debug_frame 0 : { *(.debug_frame) }
  311. .debug_str 0 : { *(.debug_str) }
  312. .debug_loc 0 : { *(.debug_loc) }
  313. .debug_macinfo 0 : { *(.debug_macinfo) }
  314. /* SGI/MIPS DWARF 2 extensions */
  315. .debug_weaknames 0 : { *(.debug_weaknames) }
  316. .debug_funcnames 0 : { *(.debug_funcnames) }
  317. .debug_typenames 0 : { *(.debug_typenames) }
  318. .debug_varnames 0 : { *(.debug_varnames) }
  319. }