2
0

max80.ld 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
  69. /*
  70. * Sections we do not need. This program cannot exit, so
  71. * fini/destructors are never needed. Exception handling
  72. * is not supported.
  73. */
  74. /DISCARD/ : {
  75. *(.note.GNU-stack)
  76. *(.gnu_debuglink)
  77. *(.gnu.lto_*)
  78. *(.discard)
  79. *(.discard.*)
  80. *(.dtors.*)
  81. *(.dtors)
  82. *(.fini_array)
  83. *(.fini_array.*)
  84. *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*)
  85. *(.eh_frame) *(.eh_frame.*)
  86. *(.gcc_except_table .gcc_except_table.*)
  87. *(.gnu_extab*)
  88. *(.exception_ranges*)
  89. *(.text.exit .text.exit.*)
  90. *crtbegin.o(*)
  91. *crt0.o(*)
  92. }
  93. PROVIDE (__executable_start = 0);
  94. /*
  95. * Make sure the output binary starts at address 0
  96. */
  97. .null 0 : {
  98. PROVIDE(___NULL = .);
  99. KEEP (*(SORT_NONE(.null)))
  100. }
  101. .init.reset _PC_RESET : ALIGN(4) {
  102. PROVIDE (___reset = .);
  103. KEEP (*(SORT_NONE(.init.reset)))
  104. }
  105. .init.irq _PC_IRQ : ALIGN(4) {
  106. PROVIDE (___irq = .);
  107. KEEP (*(SORT_NONE(.init.irq)))
  108. }
  109. /* .rwtext is in the zero page */
  110. .rwtext : ALIGN(4) {
  111. PROVIDE (__rwtext_start = .);
  112. *(.rwtext*)
  113. PROVIDE (__rwtext_end = .);
  114. }
  115. /*
  116. * Put the short data sections in the zero page.
  117. * This means the initialized sections aren't contiguous, but
  118. * all memory is intialized during FPGA load anyway.
  119. */
  120. . = ALIGN(4);
  121. __SDATA_BEGIN__ = .;
  122. .srodata : {
  123. *(.srodata*)
  124. }
  125. .sdata : {
  126. *(.sdata .sdata.* .gnu.linkonce.s.*)
  127. }
  128. .sdata2 : {
  129. *(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
  130. }
  131. . = ALIGN(32);
  132. __BSS_START__ = .;
  133. PROVIDE (__bss_start = .);
  134. .sbss (NOLOAD) : ALIGN(4) {
  135. *(.dynsbss)
  136. *(.sbss .sbss.* .gnu.linkonce.sb.*)
  137. *(.scommon)
  138. }
  139. .sbss2 (NOLOAD) : {
  140. *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)
  141. }
  142. HIDDEN($assert_zero_page = ASSERT((. <= 2048), "zero page overflow"));
  143. .bss (NOLOAD) : {
  144. *(.dynbss)
  145. *(.bss.*hot* .gnu.linkonce.b.*)
  146. *(COMMON)
  147. }
  148. . = ALIGN(32);
  149. __BSS_END__ = .;
  150. __BSS_LEN__ = __BSS_END__ - __BSS_START__;
  151. . = ALIGN(4);
  152. __BSS_END__ = .;
  153. __BSS_LEN__ = __BSS_END__ - __BSS_START__;
  154. __global_pointer$ = 0;
  155. PROVIDE(___text = .);
  156. .init : ALIGN(4) {
  157. KEEP (*(SORT_NONE(.init)))
  158. }
  159. .text.hot : ALIGN(4) {
  160. *(.text.startup .text.startup.*)
  161. *(.text.hot .text.hot.*)
  162. *(.gnu.linkonce.t.*)
  163. }
  164. PROVIDE (__etext = .);
  165. PROVIDE (_etext = .);
  166. . = ALIGN(4);
  167. .str.hot : ALIGN(4) {
  168. INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(*.hot*)
  169. }
  170. .rodata.hot : {
  171. *(.rodata.hot* .gnu.linkonce.r.*)
  172. }
  173. /* Thread Local Storage sections */
  174. .tdata : {
  175. PROVIDE_HIDDEN (__tdata_start = .);
  176. *(.tdata .tdata.* .gnu.linkonce.td.*)
  177. }
  178. .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
  179. .preinit_array : {
  180. PROVIDE_HIDDEN (__preinit_array_start = .);
  181. KEEP (*(.preinit_array))
  182. PROVIDE_HIDDEN (__preinit_array_end = .);
  183. }
  184. /* Are these necessary/supportable? */
  185. .jcr : { KEEP (*(.jcr)) }
  186. .data.rel.ro : {
  187. *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*)
  188. }
  189. .data : {
  190. __DATA_BEGIN__ = .;
  191. *(.data .data.* .gnu.linkonce.d.*)
  192. SORT(CONSTRUCTORS)
  193. }
  194. .data1 : { *(.data1) }
  195. _edata = .;
  196. _end = .;
  197. HIDDEN($sram_size_assert = ASSERT(. <= STACK_BOTTOM, "SRAM overflow"));
  198. .stack STACK_BOTTOM : {
  199. KEEP (*(.stack))
  200. }
  201. /* Sections in SDRAM */
  202. . = SDRAM_ADDR;
  203. __dram_start = .;
  204. __dram_init_start = .;
  205. .dram.abcrom : AT(SRAM_SIZE) ALIGN(4) {
  206. __abcrom_start = .;
  207. KEEP(*(SORT_NONE(.dram.abcrom*)))
  208. __abcrom_end = .;
  209. /* Make sure this section is not empty */
  210. LONG(0xffffffff)
  211. LONG(0xffffffff)
  212. LONG(0xffffffff)
  213. LONG(0xffffffff)
  214. } >DRAM
  215. .dram.text : ALIGN(4) {
  216. *(SORT(.text.sorted.*))
  217. *(.text .stub .text.*)
  218. *(.text.*unlikely*)
  219. *(.dram.text*)
  220. } >DRAM
  221. .dram.rodata : ALIGN(4) {
  222. *(.rodata* .dram.rodata*)
  223. } >DRAM
  224. .dram.str : ALIGN(4) {
  225. INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(*)
  226. }
  227. .dram.init_array : ALIGN(4) {
  228. PROVIDE_HIDDEN (__init_array_start = .);
  229. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)
  230. SORT_BY_INIT_PRIORITY(.ctors.*)))
  231. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  232. PROVIDE_HIDDEN (__init_array_end = .);
  233. } >DRAM
  234. .dram.data : ALIGN(4) {
  235. *(.dram.data* .data*)
  236. } >DRAM
  237. . = ALIGN(8);
  238. __dram_init_end = .;
  239. __dram_init_len = __dram_init_end - __dram_init_start;
  240. /* Keeps ld from getting confused */
  241. . = . + SDRAM_SIZE;
  242. /* Test program image - overlays */
  243. .dram.test __dram_init_end + SDRAM_SIZE :
  244. AT(SRAM_SIZE + __dram_init_len) ALIGN(4) {
  245. KEEP(*(.dram.test*))
  246. } >DRAM2
  247. /* bss can overlay the test program image */
  248. . = __dram_init_end;
  249. __dram_bss_start = .;
  250. .dram.bss (NOLOAD) : ALIGN(8) {
  251. *(.dram.bss* .bss*)
  252. } >DRAM
  253. . = ALIGN(8);
  254. __dram_bss_end = .;
  255. __dram_bss_len = __dram_bss_end - __dram_bss_start;
  256. /* Like BSS except no need to clear on boot */
  257. .dram.noinit (NOLOAD) : ALIGN(8) {
  258. *(.dram.noinit*)
  259. } >DRAM
  260. /* No need to zero the heap */
  261. .heap (NOLOAD) : ALIGN(16) {
  262. *(.heap*)
  263. } >DRAM
  264. __dram_end = .;
  265. /* Catch missing sections */
  266. .junk : {
  267. }
  268. }