1OUTPUT_ARCH( "riscv" )
2
3ENTRY( _start )
4
5MEMORY
6{
7    /* Run in FLASH */
8    flash (rxai!w) : ORIGIN = 0x08000000, LENGTH = 16k
9    ram   (wxa!ri) : ORIGIN = 0x20000000, LENGTH = 6k
10
11    /* Run in RAM */
12/*  flash (rxai!w) : ORIGIN = 0x20000000, LENGTH = 4k
13    ram   (wxa!ri) : ORIGIN = 0x20001000, LENGTH = 2K
14*/
15}
16
17
18SECTIONS
19{
20  __stack_size = DEFINED(__stack_size) ? __stack_size : 1K;
21
22
23  .init           :
24  {
25    KEEP (*(SORT_NONE(.init)))
26  } >flash AT>flash
27
28  .ilalign         :
29  {
30    . = ALIGN(4);
31    PROVIDE( _ilm_lma = . );
32  } >flash AT>flash
33
34  .ialign         :
35  {
36    PROVIDE( _ilm = . );
37  } >flash AT>flash
38
39  .text           :
40  {
41    *(.rodata .rodata.*)
42    *(.text.unlikely .text.unlikely.*)
43    *(.text.startup .text.startup.*)
44    *(.text .text.*)
45    *(.gnu.linkonce.t.*)
46
47    /* section information for finsh shell */
48    . = ALIGN(4);
49    __fsymtab_start = .;
50    KEEP(*(FSymTab))
51    __fsymtab_end = .;
52    . = ALIGN(4);
53    __vsymtab_start = .;
54    KEEP(*(VSymTab))
55    __vsymtab_end = .;
56    . = ALIGN(4);
57
58    /* section information for initial. */
59    . = ALIGN(4);
60    __rt_init_start = .;
61    KEEP(*(SORT(.rti_fn*)))
62    __rt_init_end = .;
63    . = ALIGN(4);
64
65    /* section information for modules */
66    . = ALIGN(4);
67    __rtmsymtab_start = .;
68    KEEP(*(RTMSymTab))
69    __rtmsymtab_end = .;
70
71  } >flash AT>flash
72
73  .fini           :
74  {
75    KEEP (*(SORT_NONE(.fini)))
76  } >flash AT>flash
77
78  . = ALIGN(4);
79
80  PROVIDE (__etext = .);
81  PROVIDE (_etext = .);/*0x80022c8*/
82  PROVIDE (etext = .);/*0x80022c8*/
83  PROVIDE( _eilm = . );
84
85  .preinit_array  :
86  {
87    PROVIDE_HIDDEN (__preinit_array_start = .);
88    KEEP (*(.preinit_array))
89    PROVIDE_HIDDEN (__preinit_array_end = .);
90  } >flash AT>flash
91
92  .init_array     :
93  {
94    PROVIDE_HIDDEN (__init_array_start = .);
95    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
96    KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
97    PROVIDE_HIDDEN (__init_array_end = .);
98  } >flash AT>flash
99
100  .fini_array     :
101  {
102    PROVIDE_HIDDEN (__fini_array_start = .);
103    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
104    KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
105    PROVIDE_HIDDEN (__fini_array_end = .);
106  } >flash AT>flash
107
108  .ctors          :
109  {
110    /* gcc uses crtbegin.o to find the start of
111       the constructors, so we make sure it is
112       first.  Because this is a wildcard, it
113       doesn't matter if the user does not
114       actually link against crtbegin.o; the
115       linker won't look for a file to match a
116       wildcard.  The wildcard also means that it
117       doesn't matter which directory crtbegin.o
118       is in.  */
119    KEEP (*crtbegin.o(.ctors))
120    KEEP (*crtbegin?.o(.ctors))
121    /* We don't want to include the .ctor section from
122       the crtend.o file until after the sorted ctors.
123       The .ctor section from the crtend file contains the
124       end of ctors marker and it must be last */
125    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
126    KEEP (*(SORT(.ctors.*)))
127    KEEP (*(.ctors))
128  } >flash AT>flash
129
130  .dtors          :
131  {
132    KEEP (*crtbegin.o(.dtors))
133    KEEP (*crtbegin?.o(.dtors))
134    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
135    KEEP (*(SORT(.dtors.*)))
136    KEEP (*(.dtors))
137  } >flash AT>flash
138
139    . = ALIGN(4);
140    PROVIDE( _eilm = . );
141
142  .lalign         :
143  {
144    . = ALIGN(4);
145    PROVIDE( _data_lma = . );
146  } >flash AT>flash
147
148  .dalign         :
149  {
150    . = ALIGN(4);
151    PROVIDE( _data = . );
152  } >ram AT>flash
153
154
155  .data          :
156  {
157    *(.rdata)
158
159    *(.gnu.linkonce.r.*)
160    *(.data .data.*)
161    *(.gnu.linkonce.d.*)
162    . = ALIGN(8);
163    PROVIDE( __global_pointer$ = . + 0x800);
164    *(.sdata .sdata.*)
165    *(.gnu.linkonce.s.*)
166    . = ALIGN(8);
167    *(.srodata.cst16)
168    *(.srodata.cst8)
169    *(.srodata.cst4)
170    *(.srodata.cst2)
171    *(.srodata .srodata.*)
172  } >ram AT>flash
173
174  . = ALIGN(4);
175  PROVIDE( _edata = . );
176  PROVIDE( edata = . );
177
178  PROVIDE( _fbss = . ); /*0X200052A0  0X200002A0*/
179  PROVIDE( __bss_start = . );
180  .bss            :
181  {
182    *(.sbss*)
183    *(.gnu.linkonce.sb.*)
184    *(.bss .bss.*)
185    *(.gnu.linkonce.b.*)
186    *(COMMON)
187    . = ALIGN(4);
188  } >ram AT>ram
189
190  . = ALIGN(8);
191  PROVIDE( _end = . ); /*0X2000,0340*/
192  PROVIDE( end = . );
193
194  .stack ORIGIN(ram) + LENGTH(ram) - __stack_size :
195  {
196    PROVIDE( _heap_end = . );
197    . = __stack_size;
198    PROVIDE( _sp = . );
199  } >ram AT>ram
200}
201