sections.ld.in 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*
  2. * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /* Default entry point */
  7. ENTRY(call_start_cpu0);
  8. SECTIONS
  9. {
  10. /**
  11. * RTC fast memory holds RTC wake stub code,
  12. * including from any source file named rtc_wake_stub*.c
  13. */
  14. .rtc.text :
  15. {
  16. . = ALIGN(4);
  17. _rtc_fast_start = ABSOLUTE(.);
  18. mapping[rtc_text]
  19. *rtc_wake_stub*.*(.literal .text .literal.* .text.*)
  20. *(.rtc_text_end_test)
  21. /* 16B padding for possible CPU prefetch and 4B alignment for PMS split lines */
  22. . += _esp_memprot_prefetch_pad_size;
  23. . = ALIGN(4);
  24. _rtc_text_end = ABSOLUTE(.);
  25. } > rtc_iram_seg
  26. /**
  27. * This section located in RTC FAST Memory area.
  28. * It holds data marked with RTC_FAST_ATTR attribute.
  29. * See the file "esp_attr.h" for more information.
  30. */
  31. .rtc.force_fast :
  32. {
  33. . = ALIGN(4);
  34. _rtc_force_fast_start = ABSOLUTE(.);
  35. mapping[rtc_force_fast]
  36. *(.rtc.force_fast .rtc.force_fast.*)
  37. . = ALIGN(4) ;
  38. _rtc_force_fast_end = ABSOLUTE(.);
  39. } > rtc_data_seg
  40. /**
  41. * RTC data section holds RTC wake stub
  42. * data/rodata, including from any source file
  43. * named rtc_wake_stub*.c and the data marked with
  44. * RTC_DATA_ATTR, RTC_RODATA_ATTR attributes.
  45. */
  46. .rtc.data :
  47. {
  48. _rtc_data_start = ABSOLUTE(.);
  49. mapping[rtc_data]
  50. *rtc_wake_stub*.*(.data .rodata .data.* .rodata.* .bss .bss.*)
  51. _rtc_data_end = ABSOLUTE(.);
  52. } > rtc_data_location
  53. /* RTC bss, from any source file named rtc_wake_stub*.c */
  54. .rtc.bss (NOLOAD) :
  55. {
  56. _rtc_bss_start = ABSOLUTE(.);
  57. *rtc_wake_stub*.*(.bss .bss.*)
  58. *rtc_wake_stub*.*(COMMON)
  59. mapping[rtc_bss]
  60. _rtc_bss_end = ABSOLUTE(.);
  61. } > rtc_data_location
  62. /**
  63. * This section holds data that should not be initialized at power up
  64. * and will be retained during deep sleep.
  65. * User data marked with RTC_NOINIT_ATTR will be placed
  66. * into this section. See the file "esp_attr.h" for more information.
  67. */
  68. .rtc_noinit (NOLOAD):
  69. {
  70. . = ALIGN(4);
  71. _rtc_noinit_start = ABSOLUTE(.);
  72. *(.rtc_noinit .rtc_noinit.*)
  73. . = ALIGN(4) ;
  74. _rtc_noinit_end = ABSOLUTE(.);
  75. } > rtc_data_location
  76. /**
  77. * This section located in RTC SLOW Memory area.
  78. * It holds data marked with RTC_SLOW_ATTR attribute.
  79. * See the file "esp_attr.h" for more information.
  80. */
  81. .rtc.force_slow :
  82. {
  83. . = ALIGN(4);
  84. _rtc_force_slow_start = ABSOLUTE(.);
  85. *(.rtc.force_slow .rtc.force_slow.*)
  86. . = ALIGN(4) ;
  87. _rtc_force_slow_end = ABSOLUTE(.);
  88. } > rtc_slow_seg
  89. /* Get size of rtc slow data based on rtc_data_location alias */
  90. _rtc_slow_length = (ORIGIN(rtc_slow_seg) == ORIGIN(rtc_data_location))
  91. ? (_rtc_force_slow_end - _rtc_data_start)
  92. : (_rtc_force_slow_end - _rtc_force_slow_start);
  93. _rtc_fast_length = (ORIGIN(rtc_slow_seg) == ORIGIN(rtc_data_location))
  94. ? (_rtc_force_fast_end - _rtc_fast_start)
  95. : (_rtc_noinit_end - _rtc_fast_start);
  96. ASSERT((_rtc_slow_length <= LENGTH(rtc_slow_seg)),
  97. "RTC_SLOW segment data does not fit.")
  98. ASSERT((_rtc_fast_length <= LENGTH(rtc_data_seg)),
  99. "RTC_FAST segment data does not fit.")
  100. .iram0.text :
  101. {
  102. _iram_start = ABSOLUTE(.);
  103. /* Vectors go to start of IRAM */
  104. ASSERT(ABSOLUTE(.) % 0x100 == 0, "vector address must be 256 byte aligned");
  105. KEEP(*(.exception_vectors.text));
  106. . = ALIGN(4);
  107. _invalid_pc_placeholder = ABSOLUTE(.);
  108. /* Code marked as running out of IRAM */
  109. _iram_text_start = ABSOLUTE(.);
  110. mapping[iram0_text]
  111. } > iram0_0_seg
  112. /**
  113. * This section is required to skip .iram0.text area because iram0_0_seg and
  114. * dram0_0_seg reflect the same address space on different buses.
  115. */
  116. .dram0.dummy (NOLOAD):
  117. {
  118. . = ORIGIN(dram0_0_seg) + _iram_end - _iram_start;
  119. } > dram0_0_seg
  120. .dram0.data :
  121. {
  122. _data_start = ABSOLUTE(.);
  123. *(.gnu.linkonce.d.*)
  124. *(.data1)
  125. __global_pointer$ = . + 0x800;
  126. *(.sdata)
  127. *(.sdata.*)
  128. *(.gnu.linkonce.s.*)
  129. *(.gnu.linkonce.s2.*)
  130. *(.jcr)
  131. mapping[dram0_data]
  132. _data_end = ABSOLUTE(.);
  133. . = ALIGN(4);
  134. } > dram0_0_seg
  135. /**
  136. * This section holds data that should not be initialized at power up.
  137. * The section located in Internal SRAM memory region. The macro _NOINIT
  138. * can be used as attribute to place data into this section.
  139. * See the "esp_attr.h" file for more information.
  140. */
  141. .noinit (NOLOAD):
  142. {
  143. . = ALIGN(4);
  144. _noinit_start = ABSOLUTE(.);
  145. *(.noinit .noinit.*)
  146. . = ALIGN(4) ;
  147. _noinit_end = ABSOLUTE(.);
  148. } > dram0_0_seg
  149. .stack :
  150. {
  151. . = ALIGN(8);
  152. __STACKSIZE__ = 40960;
  153. __stack_start__ = .;
  154. *(.stack*)
  155. . += __STACKSIZE__;
  156. __stack_cpu0 = .;
  157. __stack_end__ = .;
  158. } > dram0_0_seg
  159. PROVIDE( __rt_rvstack = __stack_end__);
  160. .heap :
  161. {
  162. . = ALIGN(8);
  163. __HEAPSIZE__ = 40960;
  164. __heap_start__ = .;
  165. . += __HEAPSIZE__;
  166. __heap_end__ = .;
  167. } > dram0_0_seg
  168. /* Shared RAM */
  169. .dram0.bss (NOLOAD) :
  170. {
  171. . = ALIGN (8);
  172. _bss_start = ABSOLUTE(.);
  173. mapping[dram0_bss]
  174. *(.dynsbss)
  175. *(.sbss)
  176. *(.sbss.*)
  177. *(.gnu.linkonce.sb.*)
  178. *(.scommon)
  179. *(.sbss2)
  180. *(.sbss2.*)
  181. *(.gnu.linkonce.sb2.*)
  182. *(.dynbss)
  183. *(.share.mem)
  184. *(.gnu.linkonce.b.*)
  185. . = ALIGN (8);
  186. _bss_end = ABSOLUTE(.);
  187. } > dram0_0_seg
  188. ASSERT(((_bss_end - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), "DRAM segment data does not fit.")
  189. .flash.text :
  190. {
  191. _stext = .;
  192. _instruction_reserved_start = ABSOLUTE(.);
  193. _text_start = ABSOLUTE(.);
  194. mapping[flash_text]
  195. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  196. *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */
  197. *(.fini.literal)
  198. *(.fini)
  199. *(.gnu.version)
  200. /* section information for finsh shell */
  201. . = ALIGN(8);
  202. __fsymtab_start = .;
  203. KEEP(*(FSymTab))
  204. __fsymtab_end = .;
  205. . = ALIGN(8);
  206. __vsymtab_start = .;
  207. KEEP(*(VSymTab))
  208. __vsymtab_end = .;
  209. . = ALIGN(8);
  210. /** CPU will try to prefetch up to 16 bytes of
  211. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  212. * safe access to up to 16 bytes after the last real instruction, add
  213. * dummy bytes to ensure this
  214. */
  215. . += _esp_flash_mmap_prefetch_pad_size;
  216. _text_end = ABSOLUTE(.);
  217. _instruction_reserved_end = ABSOLUTE(.);
  218. _etext = .;
  219. /**
  220. * Similar to _iram_start, this symbol goes here so it is
  221. * resolved by addr2line in preference to the first symbol in
  222. * the flash.text segment.
  223. */
  224. _flash_cache_start = ABSOLUTE(0);
  225. } > default_code_seg
  226. /**
  227. * This dummy section represents the .flash.text section but in default_rodata_seg.
  228. * Thus, it must have its alignment and (at least) its size.
  229. */
  230. .flash_rodata_dummy (NOLOAD):
  231. {
  232. _flash_rodata_dummy_start = .;
  233. /* Start at the same alignment constraint than .flash.text */
  234. . = ALIGN(ALIGNOF(.flash.text));
  235. /* Create an empty gap as big as .flash.text section */
  236. . = . + SIZEOF(.flash.text);
  237. /* Prepare the alignment of the section above. Few bytes (0x20) must be
  238. * added for the mapping header. */
  239. . = ALIGN(0x10000) + 0x20;
  240. _rodata_reserved_start = .;
  241. } > default_rodata_seg
  242. .flash.appdesc : ALIGN(0x10)
  243. {
  244. _rodata_start = ABSOLUTE(.);
  245. *(.rodata_desc .rodata_desc.*) /* Should be the first. App version info. DO NOT PUT ANYTHING BEFORE IT! */
  246. *(.rodata_custom_desc .rodata_custom_desc.*) /* Should be the second. Custom app version info. DO NOT PUT ANYTHING BEFORE IT! */
  247. /* Create an empty gap within this section. Thanks to this, the end of this
  248. * section will match .flash.rodata's begin address. Thus, both sections
  249. * will be merged when creating the final bin image. */
  250. . = ALIGN(ALIGNOF(.flash.rodata));
  251. } >default_rodata_seg
  252. .flash.rodata : ALIGN(0x10)
  253. {
  254. _flash_rodata_start = ABSOLUTE(.);
  255. mapping[flash_rodata]
  256. *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */
  257. *(.gnu.linkonce.r.*)
  258. *(.rodata1)
  259. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  260. *(.xt_except_table)
  261. *(.gcc_except_table .gcc_except_table.*)
  262. *(.gnu.linkonce.e.*)
  263. *(.gnu.version_r)
  264. . = (. + 7) & ~ 3;
  265. /*
  266. * C++ constructor and destructor tables
  267. * Don't include anything from crtbegin.o or crtend.o, as IDF doesn't use toolchain crt.
  268. *
  269. * RISC-V gcc is configured with --enable-initfini-array so it emits an .init_array section instead.
  270. * But the init_priority sections will be sorted for iteration in ascending order during startup.
  271. * The rest of the init_array sections is sorted for iteration in descending order during startup, however.
  272. * Hence a different section is generated for the init_priority functions which is iterated in
  273. * ascending order during startup. The corresponding code can be found in startup.c.
  274. */
  275. __init_priority_array_start = ABSOLUTE(.);
  276. KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array.*))
  277. __init_priority_array_end = ABSOLUTE(.);
  278. __init_array_start = ABSOLUTE(.);
  279. KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array))
  280. __init_array_end = ABSOLUTE(.);
  281. KEEP (*crtbegin.*(.dtors))
  282. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  283. KEEP (*(SORT(.dtors.*)))
  284. KEEP (*(.dtors))
  285. /* C++ exception handlers table: */
  286. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  287. *(.xt_except_desc)
  288. *(.gnu.linkonce.h.*)
  289. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  290. *(.xt_except_desc_end)
  291. *(.dynamic)
  292. *(.gnu.version_d)
  293. /* Addresses of memory regions reserved via SOC_RESERVE_MEMORY_REGION() */
  294. soc_reserved_memory_region_start = ABSOLUTE(.);
  295. KEEP (*(.reserved_memory_address))
  296. soc_reserved_memory_region_end = ABSOLUTE(.);
  297. /* System init functions registered via ESP_SYSTEM_INIT_FN */
  298. _esp_system_init_fn_array_start = ABSOLUTE(.);
  299. KEEP (*(SORT_BY_INIT_PRIORITY(.esp_system_init_fn.*)))
  300. _esp_system_init_fn_array_end = ABSOLUTE(.);
  301. /* section information for initial. */
  302. . = ALIGN(4);
  303. __rt_init_start = .;
  304. KEEP(*(SORT(.rti_fn*)))
  305. __rt_init_end = .;
  306. . = ALIGN(4);
  307. _rodata_end = ABSOLUTE(.);
  308. /* Literals are also RO data. */
  309. _lit4_start = ABSOLUTE(.);
  310. *(*.lit4)
  311. *(.lit4.*)
  312. *(.gnu.linkonce.lit4.*)
  313. _lit4_end = ABSOLUTE(.);
  314. . = ALIGN(4);
  315. _thread_local_start = ABSOLUTE(.);
  316. *(.tdata)
  317. *(.tdata.*)
  318. *(.tbss)
  319. *(.tbss.*)
  320. _thread_local_end = ABSOLUTE(.);
  321. _rodata_reserved_end = ABSOLUTE(.);
  322. . = ALIGN(ALIGNOF(.eh_frame));
  323. } > default_rodata_seg
  324. /* Keep this section shall be at least aligned on 4 */
  325. .eh_frame : ALIGN(8)
  326. {
  327. __eh_frame = ABSOLUTE(.);
  328. KEEP (*(.eh_frame))
  329. __eh_frame_end = ABSOLUTE(.);
  330. /* Guarantee that this section and the next one will be merged by making
  331. * them adjacent. */
  332. . = ALIGN(ALIGNOF(.eh_frame_hdr));
  333. } > default_rodata_seg
  334. /* To avoid any exception in C++ exception frame unwinding code, this section
  335. * shall be aligned on 8. */
  336. .eh_frame_hdr : ALIGN(8)
  337. {
  338. __eh_frame_hdr = ABSOLUTE(.);
  339. KEEP (*(.eh_frame_hdr))
  340. __eh_frame_hdr_end = ABSOLUTE(.);
  341. } > default_rodata_seg
  342. .flash.rodata_noload (NOLOAD) :
  343. {
  344. . = ALIGN (4);
  345. mapping[rodata_noload]
  346. } > default_rodata_seg
  347. /* Marks the end of IRAM code segment */
  348. .iram0.text_end (NOLOAD) :
  349. {
  350. /* iram_end_test section exists for use by Memprot unit tests only */
  351. *(.iram_end_test)
  352. /* ESP32-C3 memprot requires 16B padding for possible CPU prefetch and 512B alignment for PMS split lines */
  353. . += _esp_memprot_prefetch_pad_size;
  354. . = ALIGN(_esp_memprot_align_size);
  355. _iram_text_end = ABSOLUTE(.);
  356. } > iram0_0_seg
  357. .iram0.data :
  358. {
  359. . = ALIGN(16);
  360. _iram_data_start = ABSOLUTE(.);
  361. mapping[iram0_data]
  362. _iram_data_end = ABSOLUTE(.);
  363. } > iram0_0_seg
  364. .iram0.bss (NOLOAD) :
  365. {
  366. . = ALIGN(16);
  367. _iram_bss_start = ABSOLUTE(.);
  368. mapping[iram0_bss]
  369. _iram_bss_end = ABSOLUTE(.);
  370. . = ALIGN(16);
  371. _iram_end = ABSOLUTE(.);
  372. } > iram0_0_seg
  373. /* Marks the end of data, bss and possibly rodata */
  374. .dram0.heap_start (NOLOAD) :
  375. {
  376. . = ALIGN (16);
  377. _heap_start = ABSOLUTE(.);
  378. } > dram0_0_seg
  379. }
  380. ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)),
  381. "IRAM0 segment data does not fit.")
  382. ASSERT(((_heap_start - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)),
  383. "DRAM segment data does not fit.")