max80.ld 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /* -*- ld-script -*-
  2. *
  3. * Linker script for MAX80 firmware
  4. */
  5. #define __ASSEMBLY__
  6. #define __LDSCRIPT__
  7. #include "sys.h"
  8. OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv",
  9. "elf32-littleriscv")
  10. OUTPUT_ARCH(riscv)
  11. ENTRY(___reset)
  12. MEMORY
  13. {
  14. SRAM : org = SRAM_ADDR, len = SRAM_SIZE
  15. DRAM : org = SDRAM_ADDR, len = SDRAM_SIZE
  16. DRAM2 : org = SDRAM_ADDR+SDRAM_SIZE, len = SDRAM_SIZE
  17. }
  18. SECTIONS
  19. {
  20. /* Debugging sections */
  21. /* Stabs debugging sections. */
  22. .stab 0 : { *(.stab) }
  23. .stabstr 0 : { *(.stabstr) }
  24. .stab.excl 0 : { *(.stab.excl) }
  25. .stab.exclstr 0 : { *(.stab.exclstr) }
  26. .stab.index 0 : { *(.stab.index) }
  27. .stab.indexstr 0 : { *(.stab.indexstr) }
  28. .comment 0 : { *(.comment) }
  29. .gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
  30. /* DWARF debug sections.
  31. Symbols in the DWARF debugging sections are relative to the beginning
  32. of the section so we begin them at 0. */
  33. /* DWARF 1. */
  34. .debug 0 : { *(.debug) }
  35. .line 0 : { *(.line) }
  36. /* GNU DWARF 1 extensions. */
  37. .debug_srcinfo 0 : { *(.debug_srcinfo) }
  38. .debug_sfnames 0 : { *(.debug_sfnames) }
  39. /* DWARF 1.1 and DWARF 2. */
  40. .debug_aranges 0 : { *(.debug_aranges) }
  41. .debug_pubnames 0 : { *(.debug_pubnames) }
  42. /* DWARF 2. */
  43. .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
  44. .debug_abbrev 0 : { *(.debug_abbrev) }
  45. .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
  46. .debug_frame 0 : { *(.debug_frame) }
  47. .debug_str 0 : { *(.debug_str) }
  48. .debug_loc 0 : { *(.debug_loc) }
  49. .debug_macinfo 0 : { *(.debug_macinfo) }
  50. /* SGI/MIPS DWARF 2 extensions. */
  51. .debug_weaknames 0 : { *(.debug_weaknames) }
  52. .debug_funcnames 0 : { *(.debug_funcnames) }
  53. .debug_typenames 0 : { *(.debug_typenames) }
  54. .debug_varnames 0 : { *(.debug_varnames) }
  55. /* DWARF 3. */
  56. .debug_pubtypes 0 : { *(.debug_pubtypes) }
  57. .debug_ranges 0 : { *(.debug_ranges) }
  58. /* DWARF 5. */
  59. .debug_addr 0 : { *(.debug_addr) }
  60. .debug_line_str 0 : { *(.debug_line_str) }
  61. .debug_loclists 0 : { *(.debug_loclists) }
  62. .debug_macro 0 : { *(.debug_macro) }
  63. .debug_names 0 : { *(.debug_names) }
  64. .debug_rnglists 0 : { *(.debug_rnglists) }
  65. .debug_str_offsets 0 : { *(.debug_str_offsets) }
  66. .debug_sup 0 : { *(.debug_sup) }
  67. .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
  68. .riscv.attributes 0 : { KEEP(*(.riscv.attributes)) }
  69. /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
  70. /*
  71. * Sections we do not need. This program cannot exit, so
  72. * fini/destructors are never needed. Exception handling
  73. * is not supported.
  74. */
  75. /DISCARD/ : {
  76. *(.note.GNU-stack)
  77. *(.gnu_debuglink)
  78. *(.gnu.lto_*)
  79. *(.discard)
  80. *(.discard.*)
  81. *(.dtors.*)
  82. *(.dtors)
  83. *(.fini_array)
  84. *(.fini_array.*)
  85. *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*)
  86. *(.eh_frame) *(.eh_frame.*)
  87. *(.gcc_except_table .gcc_except_table.*)
  88. *(.gnu_extab*)
  89. *(.exception_ranges*)
  90. *(.text.exit .text.exit.*)
  91. *crtbegin.o(*)
  92. *crt0.o(*)
  93. }
  94. . = 0;
  95. PROVIDE (__executable_start = .);
  96. /*
  97. * Make sure the output binary starts at address 0
  98. */
  99. .null 0 : {
  100. PROVIDE(___NULL = .);
  101. KEEP (*(SORT_NONE(.null)))
  102. }
  103. .init.reset _PC_RESET : ALIGN(4) {
  104. PROVIDE (___reset = .);
  105. KEEP (*(SORT_NONE(.init.reset)))
  106. }
  107. .init.irq _PC_IRQ : ALIGN(4) {
  108. PROVIDE (___irq = .);
  109. KEEP (*(SORT_NONE(.init.irq)))
  110. }
  111. /* .rwtext is in the zero page */
  112. .rwtext : ALIGN(4) {
  113. PROVIDE (__rwtext_start = .);
  114. *(.rwtext*)
  115. PROVIDE (__rwtext_end = .);
  116. }
  117. /*
  118. * Put the short data sections in the zero page.
  119. * This means the initialized sections aren't contiguous, but
  120. * all memory is intialized during FPGA load anyway.
  121. */
  122. . = ALIGN(4);
  123. __SDATA_BEGIN__ = .;
  124. .srodata : {
  125. *(.srodata*)
  126. }
  127. .sdata : {
  128. *(.sdata .sdata.* .gnu.linkonce.s.*)
  129. }
  130. .sdata2 : {
  131. *(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
  132. }
  133. . = ALIGN(32);
  134. __BSS_START__ = .;
  135. PROVIDE (__bss_start = .);
  136. .sbss (NOLOAD) : ALIGN(4) {
  137. *(.dynsbss)
  138. *(.sbss .sbss.* .gnu.linkonce.sb.*)
  139. *(.scommon)
  140. }
  141. .sbss2 (NOLOAD) : {
  142. *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)
  143. }
  144. HIDDEN($assert_zero_page = ASSERT((. <= 2048), "zero page overflow"));
  145. .bss (NOLOAD) : {
  146. *(.dynbss)
  147. *(.bss.*hot* .gnu.linkonce.b.*)
  148. *(COMMON)
  149. }
  150. . = ALIGN(32);
  151. __BSS_END__ = .;
  152. __BSS_LEN__ = __BSS_END__ - __BSS_START__;
  153. . = ALIGN(4);
  154. __BSS_END__ = .;
  155. __BSS_LEN__ = __BSS_END__ - __BSS_START__;
  156. __global_pointer$ = 0;
  157. PROVIDE(___text = .);
  158. .init : ALIGN(4) {
  159. KEEP (*(SORT_NONE(.init)))
  160. }
  161. .text.hot : ALIGN(4) {
  162. *(.text.startup .text.startup.*)
  163. *(.text.hot .text.hot.*)
  164. *(.gnu.linkonce.t.*)
  165. }
  166. PROVIDE (__etext = .);
  167. PROVIDE (_etext = .);
  168. . = ALIGN(4);
  169. .str.hot : ALIGN(4) {
  170. *(.rodata*.hot.str*)
  171. }
  172. .rodata.hot : {
  173. *(.rodata*.hot* .gnu.linkonce.r.*)
  174. }
  175. /* Thread Local Storage sections */
  176. .tdata : {
  177. PROVIDE_HIDDEN (__tdata_start = .);
  178. *(.tdata .tdata.* .gnu.linkonce.td.*)
  179. }
  180. .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
  181. .preinit_array : {
  182. PROVIDE_HIDDEN (__preinit_array_start = .);
  183. KEEP (*(.preinit_array))
  184. PROVIDE_HIDDEN (__preinit_array_end = .);
  185. }
  186. /* Are these necessary/supportable? */
  187. .jcr : { KEEP (*(.jcr)) }
  188. .data.rel.ro : {
  189. *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*)
  190. }
  191. .data : {
  192. __DATA_BEGIN__ = .;
  193. *(.data .data.* .gnu.linkonce.d.*)
  194. SORT(CONSTRUCTORS)
  195. }
  196. .data1 : { *(.data1) }
  197. _edata = .;
  198. _end = .;
  199. HIDDEN($sram_size_assert = ASSERT(. <= STACK_BOTTOM, "SRAM overflow"));
  200. .stack STACK_BOTTOM : {
  201. KEEP (*(.stack))
  202. }
  203. /* Sections in SDRAM */
  204. . = SDRAM_ADDR;
  205. __dram_start = .;
  206. __dram_init_start = .;
  207. .dram.abcrom : AT(SRAM_SIZE) ALIGN(4) {
  208. __abcrom_start = .;
  209. KEEP(*(SORT_NONE(.dram.abcrom*)))
  210. __abcrom_end = .;
  211. /* Make sure this section is not empty */
  212. LONG(0xffffffff)
  213. LONG(0xffffffff)
  214. LONG(0xffffffff)
  215. LONG(0xffffffff)
  216. } >DRAM
  217. .dram.text : ALIGN(4) {
  218. *(SORT(.text.sorted.*))
  219. *(.text .stub .text.*)
  220. *(.text.*unlikely*)
  221. *(.dram.text*)
  222. } >DRAM
  223. .dram.str : ALIGN(4) {
  224. __dram_str_start = .;
  225. *(.rodata*.str* .dram.rodata*.str*)
  226. __dram_str_end = .;
  227. } >DRAM
  228. .dram.rodata : ALIGN(4) {
  229. __dram_rodata_start = .;
  230. *(.rodata* .dram.rodata*)
  231. __dram_rodata_end = .;
  232. } >DRAM
  233. .dram.init_array : ALIGN(4) {
  234. PROVIDE_HIDDEN (__init_array_start = .);
  235. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)
  236. SORT_BY_INIT_PRIORITY(.ctors.*)))
  237. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  238. PROVIDE_HIDDEN (__init_array_end = .);
  239. } >DRAM
  240. .dram.data : ALIGN(4) {
  241. *(.dram.data* .data*)
  242. } >DRAM
  243. . = ALIGN(8);
  244. __dram_init_end = .;
  245. __dram_init_len = __dram_init_end - __dram_init_start;
  246. /* Keeps ld from getting confused */
  247. . = . + SDRAM_SIZE;
  248. /* Test program image - overlays */
  249. .dram.test __dram_init_end + SDRAM_SIZE :
  250. AT(SRAM_SIZE + __dram_init_len) ALIGN(4) {
  251. KEEP(*(.dram.test*))
  252. } >DRAM2
  253. /* bss can overlay the test program image */
  254. . = __dram_init_end;
  255. __dram_bss_start = .;
  256. .dram.bss (NOLOAD) : ALIGN(8) {
  257. *(.dram.bss* .bss*)
  258. } >DRAM
  259. . = ALIGN(8);
  260. __dram_bss_end = .;
  261. __dram_bss_len = __dram_bss_end - __dram_bss_start;
  262. /* Like BSS except no need to clear on boot */
  263. .dram.noinit (NOLOAD) : ALIGN(8) {
  264. *(.dram.noinit*)
  265. } >DRAM
  266. /* No need to zero the heap */
  267. .heap (NOLOAD) : ALIGN(16) {
  268. *(.heap*)
  269. } >DRAM
  270. __dram_end = .;
  271. /* Catch missing sections */
  272. __junk_start = .;
  273. .junk : {
  274. *(*)
  275. }
  276. __junk_end = .;
  277. HIDDEN($assert_no_junk = ASSERT(__junk_end == __junk_start, "unknown sections present"));
  278. }