max80.ld 7.9 KB

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