metal.default.lds 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* Copyright 2019 SiFive, Inc */
  2. /* SPDX-License-Identifier: Apache-2.0 */
  3. /* ----------------------------------- */
  4. /* ----------------------------------- */
  5. OUTPUT_ARCH("riscv")
  6. ENTRY(_enter)
  7. MEMORY
  8. {
  9. ram (wxa!ri) : ORIGIN = 0x80000000, LENGTH = 0x4000
  10. flash (rxai!w) : ORIGIN = 0x20000000, LENGTH = 0x6a120 /* Originally at 0x20010000*/
  11. }
  12. PHDRS
  13. {
  14. flash PT_LOAD;
  15. ram_init PT_LOAD;
  16. itim_init PT_LOAD;
  17. ram PT_NULL;
  18. itim PT_NULL;
  19. }
  20. SECTIONS
  21. {
  22. __stack_size = DEFINED(__stack_size) ? __stack_size : 0x400;
  23. PROVIDE(__stack_size = __stack_size);
  24. __heap_size = DEFINED(__heap_size) ? __heap_size : 0x400;
  25. PROVIDE(__metal_boot_hart = 0);
  26. PROVIDE(__metal_chicken_bit = 0);
  27. .init :
  28. {
  29. KEEP (*(.text.metal.init.enter))
  30. KEEP (*(SORT_NONE(.init)))
  31. KEEP (*(.text.libgloss.start))
  32. } >flash AT>flash :flash
  33. .text :
  34. {
  35. *(.text.unlikely .text.unlikely.*)
  36. *(.text.startup .text.startup.*)
  37. *(.text .text.*)
  38. *(.itim .itim.*)
  39. *(.gnu.linkonce.t.*)
  40. } >flash AT>flash :flash
  41. .fini :
  42. {
  43. KEEP (*(SORT_NONE(.fini)))
  44. } >flash AT>flash :flash
  45. PROVIDE (__etext = .);
  46. PROVIDE (_etext = .);
  47. PROVIDE (etext = .);
  48. .rodata :
  49. {
  50. *(.rdata)
  51. *(.rodata .rodata.*)
  52. *(.gnu.linkonce.r.*)
  53. . = ALIGN(8);
  54. *(.srodata.cst16)
  55. *(.srodata.cst8)
  56. *(.srodata.cst4)
  57. *(.srodata.cst2)
  58. *(.srodata .srodata.*)
  59. } >flash AT>flash :flash
  60. . = ALIGN(4);
  61. .preinit_array :
  62. {
  63. PROVIDE_HIDDEN (__preinit_array_start = .);
  64. KEEP (*(.preinit_array))
  65. PROVIDE_HIDDEN (__preinit_array_end = .);
  66. } >flash AT>flash :flash
  67. .init_array :
  68. {
  69. PROVIDE_HIDDEN (__init_array_start = .);
  70. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  71. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  72. PROVIDE_HIDDEN (__init_array_end = .);
  73. } >flash AT>flash :flash
  74. .fini_array :
  75. {
  76. PROVIDE_HIDDEN (__fini_array_start = .);
  77. KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  78. KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  79. PROVIDE_HIDDEN (__fini_array_end = .);
  80. } >flash AT>flash :flash
  81. .ctors :
  82. {
  83. /* gcc uses crtbegin.o to find the start of
  84. the constructors, so we make sure it is
  85. first. Because this is a wildcard, it
  86. doesn't matter if the user does not
  87. actually link against crtbegin.o; the
  88. linker won't look for a file to match a
  89. wildcard. The wildcard also means that it
  90. doesn't matter which directory crtbegin.o
  91. is in. */
  92. KEEP (*crtbegin.o(.ctors))
  93. KEEP (*crtbegin?.o(.ctors))
  94. /* We don't want to include the .ctor section from
  95. the crtend.o file until after the sorted ctors.
  96. The .ctor section from the crtend file contains the
  97. end of ctors marker and it must be last */
  98. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
  99. KEEP (*(SORT(.ctors.*)))
  100. KEEP (*(.ctors))
  101. } >flash AT>flash :flash
  102. .dtors :
  103. {
  104. KEEP (*crtbegin.o(.dtors))
  105. KEEP (*crtbegin?.o(.dtors))
  106. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
  107. KEEP (*(SORT(.dtors.*)))
  108. KEEP (*(.dtors))
  109. } >flash AT>flash :flash
  110. .litimalign :
  111. {
  112. . = ALIGN(4);
  113. PROVIDE( metal_segment_itim_source_start = . );
  114. } >flash AT>flash :flash
  115. .ditimalign :
  116. {
  117. . = ALIGN(4);
  118. PROVIDE( metal_segment_itim_target_start = . );
  119. } >ram AT>flash :ram_init
  120. .itim :
  121. {
  122. *(.itim .itim.*)
  123. } >flash AT>flash :flash
  124. . = ALIGN(8);
  125. PROVIDE( metal_segment_itim_target_end = . );
  126. .lalign :
  127. {
  128. . = ALIGN(4);
  129. PROVIDE( _data_lma = . );
  130. PROVIDE( metal_segment_data_source_start = . );
  131. } >flash AT>flash :flash
  132. .dalign :
  133. {
  134. . = ALIGN(4);
  135. PROVIDE( metal_segment_data_target_start = . );
  136. } >ram AT>flash :ram_init
  137. .data :
  138. {
  139. *(.data .data.*)
  140. *(.gnu.linkonce.d.*)
  141. . = ALIGN(8);
  142. PROVIDE( __global_pointer$ = . + 0x800 );
  143. *(.sdata .sdata.* .sdata2.*)
  144. *(.gnu.linkonce.s.*)
  145. } >ram AT>flash :ram_init
  146. . = ALIGN(4);
  147. PROVIDE( _edata = . );
  148. PROVIDE( edata = . );
  149. PROVIDE( metal_segment_data_target_end = . );
  150. PROVIDE( _fbss = . );
  151. PROVIDE( __bss_start = . );
  152. PROVIDE( metal_segment_bss_target_start = . );
  153. .bss :
  154. {
  155. *(.sbss*)
  156. *(.gnu.linkonce.sb.*)
  157. *(.bss .bss.*)
  158. *(.gnu.linkonce.b.*)
  159. *(COMMON)
  160. . = ALIGN(4);
  161. } >ram AT>ram :ram
  162. . = ALIGN(8);
  163. PROVIDE( _end = . );
  164. PROVIDE( end = . );
  165. PROVIDE( metal_segment_bss_target_end = . );
  166. .stack :
  167. {
  168. PROVIDE(metal_segment_stack_begin = .);
  169. . = __stack_size;
  170. PROVIDE( _sp = . );
  171. PROVIDE(metal_segment_stack_end = .);
  172. } >ram AT>ram :ram
  173. .heap :
  174. {
  175. PROVIDE( metal_segment_heap_target_start = . );
  176. . = __heap_size;
  177. PROVIDE( metal_segment_heap_target_end = . );
  178. PROVIDE( _heap_end = . );
  179. } >ram AT>ram :ram
  180. }