kendryte.ld 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * The MEMORY command describes the location and size of blocks of memory
  3. * in the target. You can use it to describe which memory regions may be
  4. * used by the linker, and which memory regions it must avoid.
  5. */
  6. MEMORY
  7. {
  8. /*
  9. * Memory with CPU cache.
  10. *6M CPU SRAM
  11. */
  12. ram (wxa!ri) : ORIGIN = 0x80000000, LENGTH = (6 * 1024 * 1024)
  13. /*
  14. * Memory without CPU cache
  15. * 6M CPU SRAM
  16. */
  17. ram_nocache (wxa!ri) : ORIGIN = 0x40000000, LENGTH = (6 * 1024 * 1024)
  18. }
  19. PROVIDE( _rom_start = ORIGIN(rom) );
  20. PROVIDE( _rom_end = ORIGIN(rom) + LENGTH(rom) );
  21. PROVIDE( _ram_start = ORIGIN(ram) );
  22. PROVIDE( _ram_end = ORIGIN(ram) + LENGTH(ram) );
  23. PROVIDE( _io_start = 0x40000000 );
  24. PROVIDE( _io_end = _io_start + LENGTH(ram) );
  25. PROVIDE( _stack_size = 1 << 15 );
  26. /*
  27. * The OUTPUT_ARCH command specifies the machine architecture where the
  28. * argument is one of the names used in the Kendryte library.
  29. */
  30. OUTPUT_ARCH( "riscv" )
  31. /*
  32. * The ENTRY command specifies the entry point (ie. first instruction to
  33. * execute). The symbol _start is defined in crt0.S
  34. */
  35. ENTRY(_start)
  36. /*
  37. * The GROUP command is special since the listed archives will be
  38. * searched repeatedly until there are no new undefined references. We
  39. * need this since -lc depends on -lgloss and -lgloss depends on -lc. I
  40. * thought gcc would automatically include -lgcc when needed, but
  41. * in this file includes it explicitly here and I was seeing link errors
  42. * without it.
  43. */
  44. /* GROUP( -lc -lgloss -lgcc ) */
  45. /*
  46. * The linker only pays attention to the PHDRS command when generating
  47. * an ELF output file. In other cases, the linker will simply ignore PHDRS.
  48. */
  49. PHDRS
  50. {
  51. ram_ro PT_LOAD;
  52. ram_init PT_LOAD;
  53. ram PT_NULL;
  54. }
  55. /*
  56. * This is where we specify how the input sections map to output
  57. * sections.
  58. */
  59. SECTIONS
  60. {
  61. /* Program code segment, also known as a text segment */
  62. .text :
  63. {
  64. PROVIDE( _text = ABSOLUTE(.) );
  65. /* Initialization code segment */
  66. KEEP( *(.text.start) )
  67. *(.text.unlikely .text.unlikely.*)
  68. *(.text.startup .text.startup.*)
  69. /* Normal code segment */
  70. *(.text .text.*)
  71. *(.gnu.linkonce.t.*)
  72. . = ALIGN(8);
  73. PROVIDE( _etext = ABSOLUTE(.) );
  74. } >ram AT>ram :ram_ro
  75. /* Read-only data segment */
  76. .rodata :
  77. {
  78. *(.rdata)
  79. *(.rodata .rodata.*)
  80. *(.gnu.linkonce.r.*)
  81. } >ram AT>ram :ram_ro
  82. . = ALIGN(8);
  83. /* Exception handling */
  84. .eh_frame :
  85. {
  86. KEEP (*(.eh_frame)) *(.eh_frame.*)
  87. . = ALIGN(8);
  88. } >ram AT>ram :ram_ro
  89. .gnu_extab : { *(.gnu_extab) } >ram AT>ram :ram_ro
  90. .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) } >ram AT>ram :ram_ro
  91. .exception_ranges : { *(.exception_ranges .exception_ranges*) } >ram AT>ram :ram_ro
  92. /* Init array and fini array */
  93. .preinit_array :
  94. {
  95. PROVIDE_HIDDEN (__preinit_array_start = .);
  96. KEEP (*(.preinit_array))
  97. PROVIDE_HIDDEN (__preinit_array_end = .);
  98. } >ram AT>ram :ram_ro
  99. .init_array :
  100. {
  101. PROVIDE_HIDDEN (__init_array_start = .);
  102. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  103. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  104. PROVIDE_HIDDEN (__init_array_end = .);
  105. } >ram AT>ram :ram_ro
  106. .fini_array :
  107. {
  108. PROVIDE_HIDDEN (__fini_array_start = .);
  109. KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  110. KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  111. PROVIDE_HIDDEN (__fini_array_end = .);
  112. } >ram AT>ram :ram_ro
  113. .ctors :
  114. {
  115. /* gcc uses crtbegin.o to find the start of
  116. the constructors, so we make sure it is
  117. first. Because this is a wildcard, it
  118. doesn't matter if the user does not
  119. actually link against crtbegin.o; the
  120. linker won't look for a file to match a
  121. wildcard. The wildcard also means that it
  122. doesn't matter which directory crtbegin.o
  123. is in. */
  124. KEEP (*crtbegin.o(.ctors))
  125. KEEP (*crtbegin?.o(.ctors))
  126. /* We don't want to include the .ctor section from
  127. the crtend.o file until after the sorted ctors.
  128. The .ctor section from the crtend file contains the
  129. end of ctors marker and it must be last */
  130. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
  131. KEEP (*(SORT(.ctors.*)))
  132. KEEP (*(.ctors))
  133. } >ram AT>ram :ram_ro
  134. .dtors :
  135. {
  136. KEEP (*crtbegin.o(.dtors))
  137. KEEP (*crtbegin?.o(.dtors))
  138. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
  139. KEEP (*(SORT(.dtors.*)))
  140. KEEP (*(.dtors))
  141. } >ram AT>ram :ram_ro
  142. . = ALIGN(8);
  143. .lalign :
  144. {
  145. . = ALIGN(8);
  146. PROVIDE( _data_lma = . );
  147. } >ram AT>ram :ram_ro
  148. .dalign :
  149. {
  150. . = ALIGN(8);
  151. PROVIDE( _data = . );
  152. } >ram AT>ram :ram_init
  153. . = ALIGN(8);
  154. /* .data, .sdata and .srodata segment */
  155. .data :
  156. {
  157. /* Writable data segment (.data segment) */
  158. *(.data .data.*)
  159. *(.gnu.linkonce.d.*)
  160. /* Have _gp point to middle of sdata/sbss to maximize displacement range */
  161. . = ALIGN(8);
  162. PROVIDE( __global_pointer$ = ABSOLUTE(.) + 0x800);
  163. /* Writable small data segment (.sdata segment) */
  164. *(.sdata .sdata.*)
  165. *(.gnu.linkonce.s.*)
  166. /* Read-only small data segment (.srodata segment) */
  167. . = ALIGN(8);
  168. *(.srodata.cst16)
  169. *(.srodata.cst8)
  170. *(.srodata.cst4)
  171. *(.srodata.cst2)
  172. *(.srodata .srodata.*)
  173. /* Align _edata to cache line size */
  174. . = ALIGN(64);
  175. PROVIDE( _edata = ABSOLUTE(.) );
  176. } >ram AT>ram :ram_init
  177. /* .bss and .sbss segment */
  178. .bss :
  179. {
  180. PROVIDE( _bss = ABSOLUTE(.) );
  181. /* Writable uninitialized small data segment (.sbss segment)*/
  182. *(.sbss .sbss.*)
  183. *(.gnu.linkonce.sb.*)
  184. *(.scommon)
  185. /* Uninitialized writeable data section (.bss segment)*/
  186. *(.bss .bss.*)
  187. *(.gnu.linkonce.b.*)
  188. *(COMMON)
  189. . = ALIGN(8);
  190. PROVIDE( _ebss = ABSOLUTE(.) );
  191. } >ram AT>ram :ram
  192. PROVIDE( _tls_data = ABSOLUTE(.) );
  193. /*
  194. * Thread Local Storage (TLS) are per-thread global variables.
  195. * Compilers such as GCC provide a __thread keyword to mark global
  196. * variables as per-thread. Support is required in the program loader
  197. * and thread creator.
  198. */
  199. /* Thread-local data segment, .tdata (initialized tls). */
  200. .tdata :
  201. {
  202. KEEP( *(.tdata.begin) )
  203. *(.tdata .tdata.*)
  204. *(.gnu.linkonce.td.*)
  205. KEEP( *(.tdata.end) )
  206. } >ram AT>ram :ram
  207. /* Thread-local bss segment, .tbss (zero-initialized tls). */
  208. .tbss :
  209. {
  210. *(.tbss .tbss.*)
  211. *(.gnu.linkonce.tb.*)
  212. KEEP( *(.tbss.end) )
  213. } >ram AT>ram :ram
  214. /*
  215. * End of uninitalized data segement
  216. *
  217. * Actually the stack needs 16B alignment, and it won't hurt to also slightly
  218. * increase the alignment to 32 or even 64 (cache line size).
  219. *
  220. * Align _heap_start to cache line size
  221. */
  222. . = ALIGN(64);
  223. PROVIDE( _end = ABSOLUTE(.) );
  224. /* Leave 2 holes for stack & TLS, the size can set in kconfig */
  225. PROVIDE( _heap_start = ABSOLUTE(.) + _stack_size * 2 );
  226. PROVIDE( _tp0 = (_end + 63) & (-64) );
  227. PROVIDE( _tp1 = _tp0 + _stack_size );
  228. PROVIDE( _sp0 = _tp0 + _stack_size );
  229. PROVIDE( _sp1 = _tp1 + _stack_size );
  230. /* Heap end is at the end of memory, the memory size can set in kconfig */
  231. PROVIDE( _heap_end = _ram_end );
  232. }