metal.ramrodata.lds 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 = 0x20010000, LENGTH = 0x6a120
  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. .fini :
  34. {
  35. KEEP (*(SORT_NONE(.fini)))
  36. } >flash AT>flash :flash
  37. PROVIDE (__etext = .);
  38. PROVIDE (_etext = .);
  39. PROVIDE (etext = .);
  40. . = ALIGN(4);
  41. .preinit_array :
  42. {
  43. PROVIDE_HIDDEN (__preinit_array_start = .);
  44. KEEP (*(.preinit_array))
  45. PROVIDE_HIDDEN (__preinit_array_end = .);
  46. } >flash AT>flash :flash
  47. .init_array :
  48. {
  49. PROVIDE_HIDDEN (__init_array_start = .);
  50. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  51. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  52. PROVIDE_HIDDEN (__init_array_end = .);
  53. } >flash AT>flash :flash
  54. .fini_array :
  55. {
  56. PROVIDE_HIDDEN (__fini_array_start = .);
  57. KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  58. KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  59. PROVIDE_HIDDEN (__fini_array_end = .);
  60. } >flash AT>flash :flash
  61. .ctors :
  62. {
  63. /* gcc uses crtbegin.o to find the start of
  64. the constructors, so we make sure it is
  65. first. Because this is a wildcard, it
  66. doesn't matter if the user does not
  67. actually link against crtbegin.o; the
  68. linker won't look for a file to match a
  69. wildcard. The wildcard also means that it
  70. doesn't matter which directory crtbegin.o
  71. is in. */
  72. KEEP (*crtbegin.o(.ctors))
  73. KEEP (*crtbegin?.o(.ctors))
  74. /* We don't want to include the .ctor section from
  75. the crtend.o file until after the sorted ctors.
  76. The .ctor section from the crtend file contains the
  77. end of ctors marker and it must be last */
  78. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
  79. KEEP (*(SORT(.ctors.*)))
  80. KEEP (*(.ctors))
  81. } >flash AT>flash :flash
  82. .dtors :
  83. {
  84. KEEP (*crtbegin.o(.dtors))
  85. KEEP (*crtbegin?.o(.dtors))
  86. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
  87. KEEP (*(SORT(.dtors.*)))
  88. KEEP (*(.dtors))
  89. } >flash AT>flash :flash
  90. .litimalign :
  91. {
  92. . = ALIGN(4);
  93. PROVIDE( metal_segment_itim_source_start = . );
  94. } >flash AT>flash :flash
  95. .ditimalign :
  96. {
  97. . = ALIGN(4);
  98. PROVIDE( metal_segment_itim_target_start = . );
  99. } >ram AT>flash :ram_init
  100. .itim :
  101. {
  102. *(.itim .itim.*)
  103. } >flash AT>flash :flash
  104. . = ALIGN(8);
  105. PROVIDE( metal_segment_itim_target_end = . );
  106. .text :
  107. {
  108. *(.text.unlikely .text.unlikely.*)
  109. *(.text.startup .text.startup.*)
  110. *(.text .text.*)
  111. *(.gnu.linkonce.t.*)
  112. *(.itim .itim.*)
  113. } >flash AT>flash :flash
  114. .lalign :
  115. {
  116. . = ALIGN(4);
  117. PROVIDE( _data_lma = . );
  118. PROVIDE( metal_segment_data_source_start = . );
  119. } >flash AT>flash :flash
  120. .dalign :
  121. {
  122. . = ALIGN(4);
  123. PROVIDE( metal_segment_data_target_start = . );
  124. } >ram AT>flash :ram_init
  125. .data :
  126. {
  127. *(.rdata)
  128. *(.rodata .rodata.*)
  129. *(.gnu.linkonce.r.*)
  130. . = ALIGN(8);
  131. *(.srodata.cst16)
  132. *(.srodata.cst8)
  133. *(.srodata.cst4)
  134. *(.srodata.cst2)
  135. *(.srodata .srodata.*)
  136. *(.data .data.*)
  137. *(.gnu.linkonce.d.*)
  138. . = ALIGN(8);
  139. PROVIDE( __global_pointer$ = . + 0x800 );
  140. *(.sdata .sdata.* .sdata2.*)
  141. *(.gnu.linkonce.s.*)
  142. } >ram AT>flash :ram_init
  143. . = ALIGN(4);
  144. PROVIDE( _edata = . );
  145. PROVIDE( edata = . );
  146. PROVIDE( metal_segment_data_target_end = . );
  147. PROVIDE( _fbss = . );
  148. PROVIDE( __bss_start = . );
  149. PROVIDE( metal_segment_bss_target_start = . );
  150. .bss :
  151. {
  152. *(.sbss*)
  153. *(.gnu.linkonce.sb.*)
  154. *(.bss .bss.*)
  155. *(.gnu.linkonce.b.*)
  156. *(COMMON)
  157. . = ALIGN(4);
  158. } >ram AT>ram :ram
  159. . = ALIGN(8);
  160. PROVIDE( _end = . );
  161. PROVIDE( end = . );
  162. PROVIDE( metal_segment_bss_target_end = . );
  163. .stack :
  164. {
  165. PROVIDE(metal_segment_stack_begin = .);
  166. . = __stack_size;
  167. PROVIDE( _sp = . );
  168. PROVIDE(metal_segment_stack_end = .);
  169. } >ram AT>ram :ram
  170. .heap :
  171. {
  172. PROVIDE( metal_segment_heap_target_start = . );
  173. . = __heap_size;
  174. PROVIDE( metal_segment_heap_target_end = . );
  175. PROVIDE( _heap_end = . );
  176. } >ram AT>ram :ram
  177. }