1/*
2 * Copyright (c) 2022-2023 HPMicro
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6
7define memory with size = 4G;
8
9/* Regions */
10define region ILM = [from 0x00000000 size 256k];    /* ILM */
11define region DLM = [from 0x00080000 size 256k];    /* DLM */
12define region AXI_SRAM = [from 0x01200000 size 256k];
13define region NONCACHEABLE_RAM = [from 0x01240000 size 256k];
14define region AHB_SRAM = [from 0xF0400000 size 32k];
15define region APB_SRAM = [from 0xF4130000 size 16k];
16
17/* Blocks */
18define block vectors with fixed order       { section .vector_table, section .isr_vector };
19define block vectors_s with fixed order     { section .vector_s_table, section .isr_s_vector };
20define block ctors                          { section .ctors,     section .ctors.*, block with         alphabetical order { init_array } };
21define block dtors                          { section .dtors,     section .dtors.*, block with reverse alphabetical order { fini_array } };
22define block eh_frame                       { section .eh_frame,  section .eh_frame.* };
23define block tbss                           { section .tbss,      section .tbss.*  };
24define block tdata                          { section .tdata,     section .tdata.* };
25define block tls   with fixed order         { block tbss, block tdata };
26define block tdata_load                     { copy of block tdata };
27define block heap  with size = __HEAPSIZE__,  alignment = 8, /* fill =0x00, */ readwrite access { };
28define block stack with size = __STACKSIZE__, alignment = 16, /* fill =0xCD, */ readwrite access { };
29define block cherryusb_usbh_class_info with alignment = 8    { section .usbh_class_info };
30define block framebuffer with alignment = 8                  { section .framebuffer };
31define block rtthread_FSymTab                                { section FSymTab };
32define block rtthread_VSymTab                                { section VSymTab };
33define block rtthread_rti_fn with alphabetical order         { section .rti_fn* };
34define block rtthread_RTMSymTab                              { section RTMSymTab };
35
36/* Symbols */
37define exported symbol __noncacheable_start__  = start of region NONCACHEABLE_RAM;
38define exported symbol __noncacheable_end__  = end of region NONCACHEABLE_RAM + 1;
39
40define exported symbol _stack_safe = end of block stack + 1;
41define exported symbol _stack = end of block stack + 1;
42
43define exported symbol __usbh_class_info_start__ = start of block cherryusb_usbh_class_info;
44define exported symbol __usbh_class_info_end__ = end of block cherryusb_usbh_class_info + 1;
45
46define exported symbol __fsymtab_start = start of block rtthread_FSymTab;
47define exported symbol __fsymtab_end = end of block rtthread_FSymTab + 1;
48
49define exported symbol __vsymtab_start = start of block rtthread_VSymTab;
50define exported symbol __vsymtab_end = end of block rtthread_VSymTab + 1;
51
52define exported symbol __rt_init_start = start of block rtthread_rti_fn;
53define exported symbol __rt_init_end = end of block rtthread_rti_fn + 1;
54
55define exported symbol __rtmsymtab_start = start of block rtthread_RTMSymTab;
56define exported symbol __rtmsymtab_end = end of block rtthread_RTMSymTab + 1;
57
58/* Initialization */
59do not initialize                           { section .noncacheable, section .fast_ram };
60do not initialize                           { section .non_init, section .non_init.*, section .*.non_init, section .*.non_init.* };
61do not initialize                           { section .no_init, section .no_init.*, section .*.no_init, section .*.no_init.* };   // Legacy sections, kept for backwards compatibility
62do not initialize                           { section .noinit, section .noinit.*, section .*.noinit, section .*.noinit.* };       // Legacy sections, used by some SDKs/HALs
63do not initialize                           { section .backup_sram};
64
65initialize by copy with packing=auto        { section .noncacheable.init, section .fast_ram.init };
66initialize by copy with packing=none        { section .data, section .data.*, section .*.data, section .*.data.* };               // Static data sections
67initialize by copy with packing=auto        { section .sdata, section .sdata.* };
68initialize by copy with packing=auto        { section .fast, section .fast.*, section .*.fast, section .*.fast.* };               // "RAM Code" sections
69
70initialize by calling __SEGGER_init_heap    { block heap  };                                        // Init the heap if there is one
71initialize by calling __SEGGER_init_ctors   { block ctors };                                        // Call constructors for global objects which need to be constructed before reaching main (if any). Make sure this is done after setting up heap.
72
73/* Placement */
74place at start of ILM                       { symbol _start };
75place in ILM                                { block vectors, block vectors_s };                     // Vector table section
76place in ILM                                { section .fast, section .fast.* };                     // "ramfunc" section
77place in ILM with minimum size order        {
78                                              block tdata_load,                                     // Thread-local-storage load image
79                                              block ctors,                                          // Constructors block
80                                              block dtors,                                          // Destructors block
81                                              block eh_frame,                                       // Exception frames placed directly into flash overriding default placement (sections writable)
82                                              block rtthread_FSymTab,
83                                              block rtthread_VSymTab,
84                                              block rtthread_rti_fn,
85                                              block rtthread_RTMSymTab,
86                                              readonly,                                             // Catch-all for readonly data (e.g. .rodata, .srodata) // It is intended placing RO here
87                                              readexec                                              // Catch-all for (readonly) executable code (e.g. .text)
88                                            };
89
90//
91// The GNU compiler creates these exception-related sections as writeable.
92// Override the section header flag and make them readonly so they can be
93// placed into flash.
94//
95define access readonly { section .gcc_except_table, section .gcc_except_table.* };
96define access readonly { section .eh_frame, section .eh_frame.* };
97define access readonly { section .sdata.DW.* };
98
99place in AXI_SRAM                           { block cherryusb_usbh_class_info };
100place in AXI_SRAM                           { block framebuffer };
101place in AXI_SRAM                           {
102                                              block tls,                                            // Thread-local-storage block
103                                              readwrite,                                            // Catch-all for initialized/uninitialized data sections (e.g. .data, .noinit)
104                                              zeroinit                                              // Catch-all for zero-initialized data sections (e.g. .bss)
105                                            };
106place in NONCACHEABLE_RAM                   { section .noncacheable, section .noncacheable.init, section .noncacheable.bss };  // Noncacheable
107place in AHB_SRAM                           { section .ahb_sram};                                   // AHB SRAM memory
108place in APB_SRAM                           { section .backup_sram};                                // Backup SRAM memory
109place in DLM                                { section .fast_ram.init, section .fast_ram, section .fast_ram.bss};   // Fast access memory
110place in DLM                                { block heap };                                         // Heap reserved block
111place at end of DLM                         { block stack };                                        // Stack reserved block
112
113/* Keep */
114keep { section .usbh_class_info, section FSymTab, section VSymTab, section .rti_fn*, section RTMSymTab };
115