max80.ld 8.1 KB

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