2
0

max80.ld 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. *(.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.*)
  192. *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*)
  193. }
  194. .data : {
  195. __DATA_BEGIN__ = .;
  196. *(.data .data.* .gnu.linkonce.d.*)
  197. SORT(CONSTRUCTORS)
  198. }
  199. .data1 : { *(.data1) }
  200. _edata = .;
  201. _end = .;
  202. /* Patched in during FPGA compile, must immediately follow _end */
  203. .datestamp (NOLOAD) : { KEEP(*(.datestamp)) }
  204. HIDDEN($sram_size_assert = ASSERT(. <= IRQSTACK_BOTTOM, "SRAM overflow"));
  205. . = IRQSTACK_BOTTOM;
  206. .stack (NOLOAD) : {
  207. KEEP (*(.stack))
  208. }
  209. /* Sections in SDRAM */
  210. . = SDRAM_ADDR;
  211. __dram_start = .;
  212. /* Always first in DRAM for remote DMA to find fixed addresses */
  213. .dram.esplink (NOLOAD) : ALIGN(4096) {
  214. __esplink_start = .;
  215. KEEP(*(SORT_NONE(.dram.esplink.head)));
  216. *(.dram.esplink .dram.esplink.*);
  217. . = ALIGN(16);
  218. __esplink_end = .;
  219. } >DRAM
  220. . = ALIGN(4096); /* Align to a flash page */
  221. __dram_init_start = .;
  222. .dram.abcrom : AT(SRAM_SIZE) ALIGN(4096) {
  223. __abcrom_start = .;
  224. KEEP(*(SORT_NONE(.dram.abcrom*)))
  225. __abcrom_end = .;
  226. } >DRAM
  227. .dram.text : ALIGN(4) {
  228. *(SORT(.text.sorted.*))
  229. *(.text .stub .text.*)
  230. *(.text.*unlikely*)
  231. *(.dram.text*)
  232. } >DRAM
  233. .dram.str : ALIGN(4) {
  234. __dram_str_start = .;
  235. *(.rodata*.str* .dram.rodata*.str*)
  236. __dram_str_end = .;
  237. } >DRAM
  238. .dram.rodata : ALIGN(4) {
  239. __dram_rodata_start = .;
  240. *(.rodata* .dram.rodata*)
  241. __dram_rodata_end = .;
  242. } >DRAM
  243. .dram.init_array : ALIGN(4) {
  244. PROVIDE_HIDDEN (__init_array_start = .);
  245. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)
  246. SORT_BY_INIT_PRIORITY(.ctors.*)))
  247. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  248. PROVIDE_HIDDEN (__init_array_end = .);
  249. } >DRAM
  250. .dram.data : ALIGN(4) {
  251. *(.dram.data* .data*)
  252. } >DRAM
  253. . = ALIGN(8);
  254. __dram_init_end = .;
  255. __dram_init_len = __dram_init_end - __dram_init_start;
  256. /* Keeps ld from getting confused */
  257. #if 0
  258. . = . + SDRAM_SIZE;
  259. /* Test program image - overlays */
  260. .dram.test __dram_init_end + SDRAM_SIZE :
  261. AT(SRAM_SIZE + __dram_init_len) ALIGN(4) {
  262. KEEP(*(.dram.test*))
  263. } >DRAM2
  264. #endif
  265. /* bss can overlay the test program image */
  266. . = __dram_init_end;
  267. __dram_bss_start = .;
  268. .dram.bss (NOLOAD) : ALIGN(8) {
  269. *(.dram.bss* .bss*)
  270. } >DRAM
  271. . = ALIGN(8);
  272. __dram_bss_end = .;
  273. __dram_bss_len = __dram_bss_end - __dram_bss_start;
  274. /* Like BSS except no need to clear on boot */
  275. .dram.noinit (NOLOAD) : ALIGN(8) {
  276. *(.dram.noinit*)
  277. } >DRAM
  278. . = ALIGN(32);
  279. PROVIDE(__heap_start = .);
  280. . = SDRAM_ADDR + SDRAM_SIZE;
  281. PROVIDE(__heap_end = .);
  282. __dram_end = .;
  283. /* Catch missing sections */
  284. . = __dram_end;
  285. __junk_start = .;
  286. .junk : {
  287. *(*)
  288. }
  289. __junk_end = .;
  290. HIDDEN($assert_no_junk = ASSERT(__junk_end == __junk_start, "unknown sections present"));
  291. }