bootloader.lds 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* Copyright (c) 2020 StarFiveTech, Inc */
  3. OUTPUT_ARCH( "riscv" )
  4. MEMORY
  5. {
  6. rom (rx) : ORIGIN = 0x18000000, LENGTH = 64K
  7. ram (rwx) : ORIGIN = 0x18010000, LENGTH = 32K
  8. }
  9. ENTRY( _start )
  10. PHDRS
  11. {
  12. text PT_LOAD;
  13. rodata PT_LOAD;
  14. data PT_LOAD;
  15. bss PT_LOAD;
  16. }
  17. SECTIONS
  18. {
  19. __stack_size = DEFINED(__stack_size) ? __stack_size : 2K;
  20. .init ALIGN((ORIGIN(rom) + 0x0), 64) : AT(ALIGN((ORIGIN(rom) + 0x0), 64))
  21. {
  22. KEEP (*(SORT_NONE(.init)))
  23. } >rom :text
  24. .text ALIGN((ADDR(.init) + SIZEOF(.init)), 64) : AT(ALIGN((LOADADDR(.init) + SIZEOF(.init)), 64))
  25. {
  26. PROVIDE(_ftext = .);
  27. *(.text.unlikely .text.unlikely.*)
  28. *(.text.startup .text.startup.*)
  29. *(.text .text.*)
  30. *(.gnu.linkonce.t.*)
  31. PROVIDE (__etext = .);
  32. PROVIDE (_etext = .);
  33. PROVIDE (etext = .);
  34. } >rom :text
  35. .rodata ALIGN((ADDR(.text) + SIZEOF(.text)), 64) : AT(ALIGN((LOADADDR(.text) + SIZEOF(.text)), 64))
  36. {
  37. *(.rdata)
  38. *(.rodata .rodata.*)
  39. *(.gnu.linkonce.r.*)
  40. } >rom :rodata
  41. .eh_frame ALIGN((ADDR(.rodata) + SIZEOF(.rodata)), 64) : AT(ALIGN((LOADADDR(.rodata) + SIZEOF(.rodata)), 64))
  42. {
  43. *(.eh_frame)
  44. } >rom :text
  45. .srodata ALIGN((ADDR(.eh_frame) + SIZEOF(.eh_frame)), 64) : AT(ALIGN((LOADADDR(.eh_frame) + SIZEOF(.eh_frame)), 64))
  46. {
  47. *(.srodata.cst16)
  48. *(.srodata.cst8)
  49. *(.srodata.cst4)
  50. *(.srodata.cst2)
  51. *(.srodata.*)
  52. } >rom :rodata
  53. .data ALIGN((ORIGIN(ram)), 64) : AT(ALIGN((LOADADDR(.srodata) + SIZEOF(.srodata)), 64))
  54. {
  55. *(.data .data.* .gnu.linkonce.d.*)
  56. . = ALIGN(8);
  57. PROVIDE( __global_pointer$ = . + 0x800 );
  58. *(.tohost) /* TODO: Support sections that aren't explicitly listed in this linker script */
  59. } >ram :data
  60. .sdata ALIGN((ADDR(.data) + SIZEOF(.data)), 64) : AT(ALIGN((LOADADDR(.data) + SIZEOF(.data)), 64))
  61. {
  62. *(.sdata .sdata.* .gnu.linkonce.s.*)
  63. } >ram :data
  64. PROVIDE(_data = ADDR(.data));
  65. PROVIDE(_data_lma = LOADADDR(.data));
  66. PROVIDE( _edata = . );
  67. . = ALIGN(8);
  68. PROVIDE( _bss_start = . );
  69. .bss ALIGN((ADDR(.sdata) + SIZEOF(.sdata)), 64) : AT(ALIGN((LOADADDR(.sdata)), 64)) ALIGN(8)
  70. {
  71. *(.sbss*)
  72. *(.gnu.linkonce.sb.*)
  73. *(.bss .bss.*)
  74. *(.gnu.linkonce.b.*)
  75. *(COMMON)
  76. . = ALIGN(8);
  77. PROVIDE(_ebss = .);
  78. } >ram :bss
  79. PROVIDE( _end = . );
  80. PROVIDE( _bss_end = . );
  81. /*
  82. * heap_stack_region_usable_end: (ORIGIN(ram) + LENGTH(ram))
  83. * heap_stack_min_size: 4096
  84. * heap_stack_max_size: 8292
  85. */
  86. PROVIDE(_sp = ALIGN(MIN((ORIGIN(ram) + LENGTH(ram)), _bss_end + 8292) - 7, 8));
  87. /*
  88. * Protect top of stack from heap, but this will not protect the heap from
  89. * stack overruns.
  90. */
  91. PROVIDE(_heap_end = _sp - 0x100);
  92. .stack :
  93. {
  94. ASSERT(_sp >= (_bss_end + 4096), "Error: No room left for the heap and stack");
  95. }
  96. }