2
0

max80.ld 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* -*- ld-script -*-
  2. *
  3. * Linker script for MAX80 firmware
  4. */
  5. #include "sys.h"
  6. OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv",
  7. "elf32-littleriscv")
  8. OUTPUT_ARCH(riscv)
  9. ENTRY(___reset)
  10. MEMORY
  11. {
  12. SRAM : org = SRAM_ADDR, len = SRAM_SIZE
  13. DRAM : org = SDRAM_ADDR, len = SDRAM_SIZE
  14. DRAM2 : org = SDRAM_ADDR+SDRAM_SIZE, len = SDRAM_SIZE
  15. }
  16. SECTIONS
  17. {
  18. /*
  19. * Sections we do not need. This program cannot exit, so
  20. * fini/destructors are never needed. Exception handling
  21. * is not supported.
  22. */
  23. /DISCARD/ : {
  24. *(.note.GNU-stack)
  25. *(.gnu_debuglink)
  26. *(.gnu.lto_*)
  27. *(.discard)
  28. *(.discard.*)
  29. *(.dtors.*)
  30. *(.dtors)
  31. *(.fini_array)
  32. *(.fini_array.*)
  33. *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*)
  34. *(.eh_frame) *(.eh_frame.*)
  35. *(.gcc_except_table .gcc_except_table.*)
  36. *(.gnu_extab*)
  37. *(.exception_ranges*)
  38. *(.text.exit .text.exit.*)
  39. *crtbegin.o(*)
  40. *crt0.o(*)
  41. }
  42. PROVIDE (__executable_start = 0);
  43. /*
  44. * Make sure the output binary starts at address 0
  45. */
  46. .null 0 : {
  47. PROVIDE(___NULL = .);
  48. KEEP (*(SORT_NONE(.null)))
  49. }
  50. .init.reset _PC_RESET : ALIGN(4) {
  51. PROVIDE (___reset = .);
  52. KEEP (*(SORT_NONE(.init.reset)))
  53. }
  54. .init.irq _PC_IRQ : ALIGN(4) {
  55. PROVIDE (___irq = .);
  56. KEEP (*(SORT_NONE(.init.irq)))
  57. }
  58. /*
  59. * Put the short data sections in the zero page.
  60. * This means the initialized sections aren't contiguous, but
  61. * all memory is intialized during FPGA load anyway.
  62. */
  63. .sdata : ALIGN(4) {
  64. __SDATA_BEGIN__ = .;
  65. *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4)
  66. *(.srodata.cst2) *(.srodata .srodata.*)
  67. *(.sdata .sdata.* .gnu.linkonce.s.*)
  68. }
  69. .sdata2 : {
  70. *(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
  71. }
  72. . = ALIGN(32);
  73. __BSS_START__ = .;
  74. PROVIDE (__bss_start = .);
  75. .sbss (NOLOAD) : ALIGN(4) {
  76. *(.dynsbss)
  77. *(.sbss .sbss.* .gnu.linkonce.sb.*)
  78. *(.scommon)
  79. }
  80. .sbss2 (NOLOAD) : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) }
  81. HIDDEN($assert_zero_page = ASSERT((. <= 2048), "zero page overflow"));
  82. .bss (NOLOAD) : {
  83. *(.dynbss)
  84. *(.bss .bss.* .gnu.linkonce.b.*)
  85. *(COMMON)
  86. }
  87. . = ALIGN(32);
  88. __BSS_END__ = .;
  89. __BSS_LEN__ = __BSS_END__ - __BSS_START__;
  90. . = ALIGN(4);
  91. __BSS_END__ = .;
  92. __BSS_LEN__ = __BSS_END__ - __BSS_START__;
  93. __global_pointer$ = 0;
  94. PROVIDE(___text = .);
  95. .init : ALIGN(4) {
  96. KEEP (*(SORT_NONE(.init)))
  97. }
  98. .text.hot : ALIGN(4) {
  99. *(.text.hot .text.hot.*)
  100. }
  101. .text : ALIGN(4) {
  102. *(.text.startup .text.startup.*)
  103. *(SORT(.text.sorted.*))
  104. *(.text .stub .text.* .gnu.linkonce.t.*)
  105. *(.text.unlikely .text.*_unlikely .text.unlikely.*)
  106. /* .gnu.warning sections are handled specially by elf.em. */
  107. *(.gnu.warning)
  108. }
  109. PROVIDE (__etext = .);
  110. PROVIDE (_etext = .);
  111. . = ALIGN(4);
  112. .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
  113. .rodata1 : { *(.rodata1) }
  114. /* Thread Local Storage sections */
  115. .tdata : {
  116. PROVIDE_HIDDEN (__tdata_start = .);
  117. *(.tdata .tdata.* .gnu.linkonce.td.*)
  118. }
  119. .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
  120. .preinit_array : {
  121. PROVIDE_HIDDEN (__preinit_array_start = .);
  122. KEEP (*(.preinit_array))
  123. PROVIDE_HIDDEN (__preinit_array_end = .);
  124. }
  125. .init_array : {
  126. PROVIDE_HIDDEN (__init_array_start = .);
  127. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)
  128. SORT_BY_INIT_PRIORITY(.ctors.*)))
  129. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  130. PROVIDE_HIDDEN (__init_array_end = .);
  131. }
  132. /* Are these necessary/supportable? */
  133. .jcr : { KEEP (*(.jcr)) }
  134. .data.rel.ro : {
  135. *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*)
  136. }
  137. .data : {
  138. __DATA_BEGIN__ = .;
  139. *(.data .data.* .gnu.linkonce.d.*)
  140. SORT(CONSTRUCTORS)
  141. }
  142. .data1 : { *(.data1) }
  143. _edata = .;
  144. _end = .;
  145. HIDDEN($sram_size_assert = ASSERT(. <= STACK_BOTTOM, "SRAM overflow"));
  146. .stack STACK_BOTTOM : {
  147. KEEP (*(.stack))
  148. }
  149. /* Sections in SDRAM */
  150. . = SDRAM_ADDR;
  151. __dram_start = .;
  152. __dram_init_start = .;
  153. .dram.abcrom : AT(SRAM_SIZE) ALIGN(4) {
  154. __abcrom_start = .;
  155. KEEP(*(SORT_NONE(.dram.abcrom*)))
  156. __abcrom_end = .;
  157. /* Make sure this section is not empty */
  158. LONG(0xffffffff)
  159. LONG(0xffffffff)
  160. LONG(0xffffffff)
  161. LONG(0xffffffff)
  162. } >DRAM
  163. .dram.text : ALIGN(4) {
  164. *(.dram.text*)
  165. } >DRAM
  166. .dram.rodata : ALIGN(4) {
  167. *(.dram.rodata*)
  168. } >DRAM
  169. .dram.data : ALIGN(4) {
  170. *(.dram.data*)
  171. } >DRAM
  172. . = ALIGN(8);
  173. __dram_init_end = .;
  174. __dram_init_len = __dram_init_end - __dram_init_start;
  175. /* Keeps ld from getting confused */
  176. . = . + SDRAM_SIZE;
  177. /* Test program image - overlays */
  178. .dram.test __dram_init_end + SDRAM_SIZE :
  179. AT(SRAM_SIZE + __dram_init_len) ALIGN(4) {
  180. KEEP(*(.dram.test*))
  181. } >DRAM2
  182. /* bss can overlay the test program image */
  183. . = __dram_init_end;
  184. __dram_bss_start = .;
  185. .dram.bss (NOLOAD) : ALIGN(8) {
  186. *(.dram.bss*)
  187. } >DRAM
  188. . = ALIGN(8);
  189. __dram_bss_end = .;
  190. __dram_bss_len = __dram_bss_end - __dram_bss_start;
  191. /* Like BSS except no need to clear on boot */
  192. .dram.noinit (NOLOAD) : ALIGN(8) {
  193. *(.dram.noinit*)
  194. } >DRAM
  195. /* No need to zero the heap */
  196. .heap (NOLOAD) : ALIGN(16) {
  197. *(.heap)
  198. } >DRAM
  199. __dram_end = .;
  200. }