1# Copyright (C) 2014-2017 Free Software Foundation, Inc.
2# 
3# Copying and distribution of this file, with or without modification,
4# are permitted in any medium without royalty provided the copyright
5# notice and this notice are preserved.
6#
7# Unusual variables checked by this code:
8#	NOP - four byte opcode for no-op (defaults to 0)
9#	NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not
10#		empty.
11#	SMALL_DATA_CTOR - .ctors contains small data.
12#	SMALL_DATA_DTOR - .dtors contains small data.
13#	DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
14#	INITIAL_READONLY_SECTIONS - at start of text segment
15#	OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
16#		(e.g., .PARISC.milli)
17#	OTHER_TEXT_SECTIONS - these get put in .text when relocating
18#	OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
19#		(e.g., .PARISC.global)
20#	OTHER_RELRO_SECTIONS - other than .data.rel.ro ...
21#		(e.g. PPC32 .fixup, .got[12])
22#	OTHER_BSS_SECTIONS - other than .bss .sbss ...
23#	ATTRS_SECTIONS - at the end
24#	OTHER_SECTIONS - at the end
25#	EXECUTABLE_SYMBOLS - symbols that must be defined for an
26#		executable (e.g., _DYNAMIC_LINK)
27#       TEXT_START_ADDR - the first byte of the text segment, after any
28#               headers.
29#       TEXT_BASE_ADDRESS - the first byte of the text segment.
30#	TEXT_START_SYMBOLS - symbols that appear at the start of the
31#		.text section.
32#	DATA_START_SYMBOLS - symbols that appear at the start of the
33#		.data section.
34#	DATA_END_SYMBOLS - symbols that appear at the end of the
35#		writeable data sections.
36#	OTHER_GOT_SYMBOLS - symbols defined just before .got.
37#	OTHER_GOT_SECTIONS - sections just after .got.
38#	OTHER_SDATA_SECTIONS - sections just after .sdata.
39#	OTHER_BSS_SYMBOLS - symbols that appear at the start of the
40#		.bss section besides ___bss_start.
41#	DATA_PLT - .plt should be in data segment, not text segment.
42#	PLT_BEFORE_GOT - .plt just before .got when .plt is in data segement.
43#	BSS_PLT - .plt should be in bss segment
44#	NO_REL_RELOCS - Don't include .rel.* sections in script
45#	NO_RELA_RELOCS - Don't include .rela.* sections in script
46#	NON_ALLOC_DYN - Place dynamic sections after data segment.
47#	TEXT_DYNAMIC - .dynamic in text segment, not data segment.
48#	EMBEDDED - whether this is for an embedded system. 
49#	SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
50#		start address of shared library.
51#	INPUT_FILES - INPUT command of files to always include
52#	WRITABLE_RODATA - if set, the .rodata section should be writable
53#	INIT_START, INIT_END -  statements just before and just after
54# 	combination of .init sections.
55#	FINI_START, FINI_END - statements just before and just after
56# 	combination of .fini sections.
57#	STACK_ADDR - start of a .stack section.
58#	OTHER_SYMBOLS - symbols to place right at the end of the script.
59#	ETEXT_NAME - name of a symbol for the end of the text section,
60#		normally etext.
61#	SEPARATE_GOTPLT - if set, .got.plt should be separate output section,
62#		so that .got can be in the RELRO area.  It should be set to
63#		the number of bytes in the beginning of .got.plt which can be
64#		in the RELRO area as well.
65#	USER_LABEL_PREFIX - prefix to add to user-visible symbols.
66#
67# When adding sections, do note that the names of some sections are used
68# when specifying the start address of the next.
69#
70
71#  Many sections come in three flavours.  There is the 'real' section,
72#  like ".data".  Then there are the per-procedure or per-variable
73#  sections, generated by -ffunction-sections and -fdata-sections in GCC,
74#  and useful for --gc-sections, which for a variable "foo" might be
75#  ".data.foo".  Then there are the linkonce sections, for which the linker
76#  eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
77#  The exact correspondences are:
78#
79#  Section	Linkonce section
80#  .text	.gnu.linkonce.t.foo
81#  .rodata	.gnu.linkonce.r.foo
82#  .data	.gnu.linkonce.d.foo
83#  .bss		.gnu.linkonce.b.foo
84#  .sdata	.gnu.linkonce.s.foo
85#  .sbss	.gnu.linkonce.sb.foo
86#  .sdata2	.gnu.linkonce.s2.foo
87#  .sbss2	.gnu.linkonce.sb2.foo
88#  .debug_info	.gnu.linkonce.wi.foo
89#  .tdata	.gnu.linkonce.td.foo
90#  .tbss	.gnu.linkonce.tb.foo
91#  .lrodata	.gnu.linkonce.lr.foo
92#  .ldata	.gnu.linkonce.l.foo
93#  .lbss	.gnu.linkonce.lb.foo
94#
95#  Each of these can also have corresponding .rel.* and .rela.* sections.
96
97
98test -z "$ENTRY" && ENTRY=_start
99test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
100test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
101if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
102test -z "${ELFSIZE}" && ELFSIZE=32
103test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
104test "$LD_FLAG" = "N" && DATA_ADDR=.
105test -z "${ETEXT_NAME}" && ETEXT_NAME=etext
106test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
107test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
108test -n "$RELRO_NOW" && unset SEPARATE_GOTPLT
109test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }"
110DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
111DATA_SEGMENT_RELRO_END=""
112DATA_SEGMENT_END=""
113if test -n "${COMMONPAGESIZE}"; then
114  DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
115  DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
116  DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
117fi
118if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
119  INITIAL_READONLY_SECTIONS=".interp       ${RELOCATING-0} : { *(.interp) }"
120fi
121if test -z "$PLT"; then
122  PLT=".plt          ${RELOCATING-0} : { *(.plt) }"
123fi
124test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT=yes
125if test -z "$GOT"; then
126  if test -z "$SEPARATE_GOTPLT"; then
127    GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.got) }"
128  else
129    GOT=".got          ${RELOCATING-0} : { *(.got) }"
130    GOTPLT=".got.plt      ${RELOCATING-0} : { *(.got.plt) }"
131  fi
132fi
133DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
134RODATA=".rodata ${RELOCATING+ADDR(.data)+SIZEOF(.data)} ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }  /*> INTERNAL_RAM*/"
135DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }"
136DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) }"
137if test -z "${NO_SMALL_DATA}"; then
138  SBSS=".sbss         ${RELOCATING-0} :
139  {
140    ${RELOCATING+${SBSS_START_SYMBOLS}}
141    ${CREATE_SHLIB+*(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)}
142    *(.dynsbss)
143    *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
144    *(.scommon)
145    ${RELOCATING+${SBSS_END_SYMBOLS}}
146  }"
147  SBSS2=".sbss2        ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
148  SDATA="/* We want the small data sections together, so single-instruction offsets
149     can access them all, and initialized data all before uninitialized, so
150     we can shorten the on-disk segment size.  */
151  .sdata        ${RELOCATING-0} : 
152  {
153    ${RELOCATING+${SDATA_START_SYMBOLS}}
154    ${CREATE_SHLIB+*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)}
155    *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
156  }"
157  SDATA2=".sdata2       ${RELOCATING-0} :
158  {
159    ${RELOCATING+${SDATA2_START_SYMBOLS}}
160    *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*})
161  }"
162  REL_SDATA=".rel.sdata    ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
163  .rela.sdata   ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
164  REL_SBSS=".rel.sbss     ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
165  .rela.sbss    ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
166  REL_SDATA2=".rel.sdata2   ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
167  .rela.sdata2  ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
168  REL_SBSS2=".rel.sbss2    ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
169  .rela.sbss2   ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
170else
171  NO_SMALL_DATA=" "
172fi
173if test -z "${DATA_GOT}"; then
174  if test -n "${NO_SMALL_DATA}"; then
175    DATA_GOT=" "
176  fi
177fi
178if test -z "${SDATA_GOT}"; then
179  if test -z "${NO_SMALL_DATA}"; then
180    SDATA_GOT=" "
181  fi
182fi
183test -n "$SEPARATE_GOTPLT" && SEPARATE_GOTPLT=" "
184test "${LARGE_SECTIONS}" = "yes" && REL_LARGE="
185  .rel.ldata    ${RELOCATING-0} : { *(.rel.ldata${RELOCATING+ .rel.ldata.* .rel.gnu.linkonce.l.*}) }
186  .rela.ldata   ${RELOCATING-0} : { *(.rela.ldata${RELOCATING+ .rela.ldata.* .rela.gnu.linkonce.l.*}) }
187  .rel.lbss     ${RELOCATING-0} : { *(.rel.lbss${RELOCATING+ .rel.lbss.* .rel.gnu.linkonce.lb.*}) }
188  .rela.lbss    ${RELOCATING-0} : { *(.rela.lbss${RELOCATING+ .rela.lbss.* .rela.gnu.linkonce.lb.*}) }
189  .rel.lrodata  ${RELOCATING-0} : { *(.rel.lrodata${RELOCATING+ .rel.lrodata.* .rel.gnu.linkonce.lr.*}) }
190  .rela.lrodata ${RELOCATING-0} : { *(.rela.lrodata${RELOCATING+ .rela.lrodata.* .rela.gnu.linkonce.lr.*}) }"
191test "${LARGE_SECTIONS}" = "yes" && OTHER_BSS_SECTIONS="
192  ${OTHER_BSS_SECTIONS}
193  .lbss ${RELOCATING-0} :
194  {
195    *(.dynlbss)
196    *(.lbss${RELOCATING+ .lbss.* .gnu.linkonce.lb.*})
197    *(LARGE_COMMON)
198  }"
199test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS="
200  .lrodata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
201  {
202    *(.lrodata${RELOCATING+ .lrodata.* .gnu.linkonce.lr.*})
203  }
204  .ldata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
205  {
206    *(.ldata${RELOCATING+ .ldata.* .gnu.linkonce.l.*})
207    ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
208  }"
209CTOR=".ctors    ADDR(.text) + SIZEOF(.text)      ${CONSTRUCTING-0} : 
210  {
211    ${CONSTRUCTING+${CTOR_START}}
212    /* gcc uses crtbegin.o to find the start of
213       the constructors, so we make sure it is
214       first.  Because this is a wildcard, it
215       doesn't matter if the user does not
216       actually link against crtbegin.o; the
217       linker won't look for a file to match a
218       wildcard.  The wildcard also means that it
219       doesn't matter which directory crtbegin.o
220       is in.  */
221
222    KEEP (*crtbegin.o(.ctors))
223    KEEP (*crtbegin?.o(.ctors))
224
225    /* We don't want to include the .ctor section from
226       the crtend.o file until after the sorted ctors.
227       The .ctor section from the crtend file contains the
228       end of ctors marker and it must be last */
229
230    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
231    KEEP (*(SORT(.ctors.*)))
232    KEEP (*(.ctors))
233    ${CONSTRUCTING+${CTOR_END}}
234  }  /*> INTERNAL_RAM*/" 
235DTOR=".dtors     ADDR(.ctors) + SIZEOF(.ctors)    ${CONSTRUCTING-0} :
236  {
237    ${CONSTRUCTING+${DTOR_START}}
238    KEEP (*crtbegin.o(.dtors))
239    KEEP (*crtbegin?.o(.dtors))
240    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
241    KEEP (*(SORT(.dtors.*)))
242    KEEP (*(.dtors))
243    ${CONSTRUCTING+${DTOR_END}}
244  }   /*> INTERNAL_RAM*/ "
245STACK="  .stack        ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
246  {
247    ${RELOCATING+___stack = .;}
248    *(.stack)
249  }"
250
251# If this is for an embedded system, don't add SIZEOF_HEADERS.
252if [ -z "$EMBEDDED" ]; then
253   test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
254else
255   test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
256fi
257
258cat <<EOF
259/* Copyright (C) 2014-2017 Free Software Foundation, Inc.
260
261   Copying and distribution of this script, with or without modification,
262   are permitted in any medium without royalty provided the copyright
263   notice and this notice are preserved.  */
264
265OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
266	      "${LITTLE_OUTPUT_FORMAT}")
267OUTPUT_ARCH(${OUTPUT_ARCH})
268${RELOCATING+ENTRY(${ENTRY})}
269
270${RELOCATING+${EXECUTABLE_SYMBOLS}}
271${RELOCATING+${INPUT_FILES}}
272${RELOCATING- /* For some reason, the Solaris linker makes bad executables
273  if gld -r is used and the intermediate file has sections starting
274  at non-zero addresses.  Could be a Solaris ld bug, could be a GNU ld
275  bug.  But for now assigning the zero vmas works.  */}
276
277
278
279/* BSP specific*/
280__PROG_SIZE_FOR_CORE__ = 1M;
281__HEAP_SIZE_FOR_CORE__ = 1M;
282
283__MAX_NUM_CORES_IN_ROWS__ = 4;
284__MAX_NUM_CORES_IN_COLS__ = 4;
285
286__FIRST_CORE_ROW_ = 0x20;
287__FIRST_CORE_COL_ = 0x24;
288
289
290
291PROVIDE (__CORE_ROW_ = __FIRST_CORE_ROW_);
292PROVIDE (__CORE_COL_ = __FIRST_CORE_COL_);
293/* generic don't touch */
294/* used to calculated the slice address in the external memory*/
295__CORE_NUM_ =  (__CORE_ROW_ -  __FIRST_CORE_ROW_ )* __MAX_NUM_CORES_IN_COLS__ + (__CORE_COL_ - __FIRST_CORE_COL_ ) ;
296
297
298MEMORY
299 {
300 	EXTERNAL_DRAM_0 (WXAI) :     ORIGIN = 0x80000000,      LENGTH = 0x1000000  /*.text, data, rodata, bss and .stack*/
301    EXTERNAL_DRAM_1 (WXAI) :        ORIGIN = 0x81000000,      LENGTH = 0x1000000 /*.heap */
302    
303    EXTERNAL_SRAM (WXAI) :       ORIGIN = 0x92000000,      LENGTH =   8K /* small external RAM, used for testing*/
304    
305    /* run time lib and crt0*/
306    RESERVED_CRT0_RAM (WXAI) :    ORIGIN = 0,      LENGTH = 0x400
307    
308    /* user program, per bank usage */
309    BANK0_SRAM (WXAI) : ORIGIN = LENGTH(RESERVED_CRT0_RAM),   LENGTH = 8K - LENGTH(RESERVED_CRT0_RAM)
310    BANK1_SRAM (WXAI) : ORIGIN = 0x2000, LENGTH = 8K
311    BANK2_SRAM (WXAI) : ORIGIN = 0x4000, LENGTH = 8K
312    BANK3_SRAM (WXAI) : ORIGIN = 0x6000, LENGTH = 8K
313    
314    /* user program, continious placement */
315    INTERNAL_RAM        (WXAI) :     ORIGIN = LENGTH(RESERVED_CRT0_RAM),  LENGTH = 32K - LENGTH(RESERVED_CRT0_RAM)
316    
317    MMR (WAI) 	      : ORIGIN = 0xF000, LENGTH = 32K
318       
319    /* multi cores space */   
320	CORE_0x20_0x24_INTERNAL_RAM :      ORIGIN = 0x82400000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
321	CORE_0x20_0x25_INTERNAL_RAM :      ORIGIN = 0x82500000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
322	CORE_0x20_0x26_INTERNAL_RAM :      ORIGIN = 0x82600000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
323	CORE_0x20_0x27_INTERNAL_RAM :      ORIGIN = 0x82700000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
324	CORE_0x21_0x24_INTERNAL_RAM :      ORIGIN = 0x86400000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
325	CORE_0x21_0x25_INTERNAL_RAM :      ORIGIN = 0x86500000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
326	CORE_0x21_0x26_INTERNAL_RAM :      ORIGIN = 0x86600000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
327	CORE_0x21_0x27_INTERNAL_RAM :      ORIGIN = 0x86700000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
328	CORE_0x22_0x24_INTERNAL_RAM :      ORIGIN = 0x8a400000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
329	CORE_0x22_0x25_INTERNAL_RAM :      ORIGIN = 0x8a500000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
330	CORE_0x22_0x26_INTERNAL_RAM :      ORIGIN = 0x8a600000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
331	CORE_0x22_0x27_INTERNAL_RAM :      ORIGIN = 0x8a700000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
332	CORE_0x23_0x24_INTERNAL_RAM :      ORIGIN = 0x8e400000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
333	CORE_0x23_0x25_INTERNAL_RAM :      ORIGIN = 0x8e500000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
334	CORE_0x23_0x26_INTERNAL_RAM :      ORIGIN = 0x8e600000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
335	CORE_0x23_0x27_INTERNAL_RAM :      ORIGIN = 0x8e700000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
336	CORE_0x24_0x24_INTERNAL_RAM :      ORIGIN = 0x82000000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
337   
338 }
339
340
341SECTIONS
342{
343
344   IVT 0 : {*.o(IVT)  } > RESERVED_CRT0_RAM
345   RESERVED_CRT0 : {*.o(RESERVED_CRT0)  } > RESERVED_CRT0_RAM
346   RESERVED_CRT0 : {*.o(reserved_crt0)  } > RESERVED_CRT0_RAM
347   
348   CORE_RAM_0 :   {*.o(core_ram_0)  }  > BANK0_SRAM
349   CORE_RAM_1 :   {*.o(core_ram_1)  }  > BANK1_SRAM
350   CORE_RAM_2 :   {*.o(core_ram_2)  }  > BANK2_SRAM
351   CORE_RAM_3 :   {*.o(core_ram_3)  }  > BANK3_SRAM
352   
353   SRAM_SOUTH :  {*.o(sram)  }  > EXTERNAL_SRAM
354   DRAM_WEST :  {*.o(dram)  }  > EXTERNAL_DRAM_1
355   
356   CORE_INTERNAL :  {*.o(core_ram_internal)  }    /*> INTERNAL_RAM*/
357   
358   /* the newlib  (libc and libm)  library is maped to the dedicated section */
359   
360   __new_lib_start_external_ =  ( ORIGIN(EXTERNAL_DRAM_0) + __PROG_SIZE_FOR_CORE__ *__CORE_NUM_ );
361   __new_lib_start_ = DEFINED(__USE_INTERNAL_MEM_FOR_NEW_LIB_) ? ORIGIN(BANK1_SRAM) :  __new_lib_start_external_ ;
362   
363   NEW_LIB_RO ${RELOCATING+__new_lib_start_} : { lib_a-*.o(.text  .rodata )  *.o(libgloss_epiphany)  }  /*  > INTERNAL_RAM*/
364   GNU_C_BUILTIN_LIB_RO     ADDR(NEW_LIB_RO) + SIZEOF(NEW_LIB_RO) : {  
365   								*mulsi3.o(.text  .rodata)  *modsi3.o(.text  .rodata)
366   								*divsi3.o(.text  .rodata)  	*udivsi3.o(.text  .rodata)
367   							    *umodsi3.o(.text  .rodata)   _*.o(.text  .rodata) 
368   } 
369 					 								
370   NEW_LIB_WR   ADDR(GNU_C_BUILTIN_LIB_RO) + SIZEOF(GNU_C_BUILTIN_LIB_RO)  : { lib_a-*.o(.data ) }    /* >  INTERNAL_RAM*/ 
371   
372   
373   __init_start = DEFINED(__USE_INTERNAL_MEM_) ? ORIGIN(BANK1_SRAM) :  (ADDR(NEW_LIB_WR) + SIZEOF(NEW_LIB_WR) ) ; 
374   __init_start = DEFINED(__USE_INTERNAL_MEM_FOR_NEW_LIB_) ? ADDR(NEW_LIB_WR) + SIZEOF(NEW_LIB_WR)  : __init_start;
375   
376
377  /* Read-only sections, merged into text segment: */
378  /*${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}*/
379  ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
380  ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
381  ${INITIAL_READONLY_SECTIONS}
382  .note.gnu.build-id : { *(.note.gnu.build-id) }
383EOF
384
385test -n "${RELOCATING+0}" || unset NON_ALLOC_DYN
386test -z "${NON_ALLOC_DYN}" || TEXT_DYNAMIC=
387cat > ldscripts/dyntmp.$$ <<EOF
388  ${TEXT_DYNAMIC+${DYNAMIC}}
389  .hash         ${RELOCATING-0} : { *(.hash) }
390  .gnu.hash     ${RELOCATING-0} : { *(.gnu.hash) }
391  .dynsym       ${RELOCATING-0} : { *(.dynsym) }
392  .dynstr       ${RELOCATING-0} : { *(.dynstr) }
393  .gnu.version  ${RELOCATING-0} : { *(.gnu.version) }
394  .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
395  .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
396EOF
397
398if [ "x$COMBRELOC" = x ]; then
399  COMBRELOCCAT="cat >> ldscripts/dyntmp.$$"
400else
401  COMBRELOCCAT="cat > $COMBRELOC"
402fi
403eval $COMBRELOCCAT <<EOF
404  .rel.init     ${RELOCATING-0} : { *(.rel.init) }
405  .rela.init    ${RELOCATING-0} : { *(.rela.init) }
406  .rel.text     ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
407  .rela.text    ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
408  .rel.fini     ${RELOCATING-0} : { *(.rel.fini) }
409  .rela.fini    ${RELOCATING-0} : { *(.rela.fini) }
410  .rel.rodata   ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
411  .rela.rodata  ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
412  ${OTHER_READONLY_RELOC_SECTIONS}
413  .rel.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+* .rel.gnu.linkonce.d.rel.ro.*}) }
414  .rela.data.rel.ro ${RELOCATING-0} : { *(.rela.data.rel.ro${RELOCATING+* .rela.gnu.linkonce.d.rel.ro.*}) }
415  .rel.data     ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
416  .rela.data    ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
417  .rel.tdata	${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
418  .rela.tdata	${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
419  .rel.tbss	${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
420  .rela.tbss	${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
421  .rel.ctors    ${RELOCATING-0} : { *(.rel.ctors) }
422  .rela.ctors   ${RELOCATING-0} : { *(.rela.ctors) }
423  .rel.dtors    ${RELOCATING-0} : { *(.rel.dtors) }
424  .rela.dtors   ${RELOCATING-0} : { *(.rela.dtors) }
425  .rel.got      ${RELOCATING-0} : { *(.rel.got) }
426  .rela.got     ${RELOCATING-0} : { *(.rela.got) }
427  ${OTHER_GOT_RELOC_SECTIONS}
428  ${REL_SDATA}
429  ${REL_SBSS}
430  ${REL_SDATA2}
431  ${REL_SBSS2}
432  .rel.bss      ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
433  .rela.bss     ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
434  ${REL_LARGE}
435EOF
436
437if [ -n "$COMBRELOC" ]; then
438cat >> ldscripts/dyntmp.$$ <<EOF
439  .rel.dyn      ${RELOCATING-0} :
440    {
441EOF
442sed -e '/^[ 	]*[{}][ 	]*$/d;/:[ 	]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/      \1/' $COMBRELOC >> ldscripts/dyntmp.$$
443cat >> ldscripts/dyntmp.$$ <<EOF
444    }
445  .rela.dyn     ${RELOCATING-0} :
446    {
447EOF
448sed -e '/^[ 	]*[{}][ 	]*$/d;/:[ 	]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/      \1/' $COMBRELOC >> ldscripts/dyntmp.$$
449cat >> ldscripts/dyntmp.$$ <<EOF
450    }
451EOF
452fi
453
454cat >> ldscripts/dyntmp.$$ <<EOF
455  .rel.plt      ${RELOCATING-0} : { *(.rel.plt) }
456  .rela.plt     ${RELOCATING-0} : { *(.rela.plt) }
457  ${OTHER_PLT_RELOC_SECTIONS}
458EOF
459
460if test -z "${NON_ALLOC_DYN}"; then
461  if test -z "${NO_REL_RELOCS}${NO_RELA_RELOCS}"; then
462    cat ldscripts/dyntmp.$$
463  else
464    if test -z "${NO_REL_RELOCS}"; then
465      sed -e '/^[ 	]*\.rela\.[^}]*$/,/}/d' -e '/^[ 	]*\.rela\./d' ldscripts/dyntmp.$$
466    fi
467    if test -z "${NO_RELA_RELOCS}"; then
468      sed -e '/^[ 	]*\.rel\.[^}]*$/,/}/d' -e '/^[ 	]*\.rel\./d' ldscripts/dyntmp.$$
469    fi
470  fi
471  rm -f ldscripts/dyntmp.$$
472fi
473
474cat <<EOF
475 
476  .init  __init_start  : 
477  {   
478    ${RELOCATING+${INIT_START}}
479    KEEP (*(.init))
480    ${RELOCATING+${INIT_END}}
481  }     /*> INTERNAL_RAM*/ =${NOP-0}
482
483  ${TEXT_PLT+${PLT}}
484  ${TINY_READONLY_SECTION}
485  
486  .fini ${RELOCATING+ADDR(.init)+SIZEOF(.init)} ${RELOCATING-0} :
487  {
488    ${RELOCATING+${FINI_START}}
489    KEEP (*(.fini))
490    ${RELOCATING+${FINI_END}}
491  }    /*> INTERNAL_RAM*/ =${NOP-0}
492  
493  .text ${RELOCATING+ADDR(.fini)+SIZEOF(.fini)} ${RELOCATING-0} :
494  {
495    ${RELOCATING+${TEXT_START_SYMBOLS}}
496    *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
497    /* .gnu.warning sections are handled specially by elf32.em.  */
498    *(.gnu.warning)
499    ${RELOCATING+${OTHER_TEXT_SECTIONS}}
500  }    /*> INTERNAL_RAM */ =${NOP-0}
501
502  ${RELOCATING+PROVIDE (__${ETEXT_NAME} = .);}
503  ${RELOCATING+PROVIDE (_${ETEXT_NAME} = .);}
504  ${RELOCATING+PROVIDE (${ETEXT_NAME} = .);}
505  ${WRITABLE_RODATA-${RODATA}}
506  .rodata1      ${RELOCATING-0} : { *(.rodata1) } 
507  ${CREATE_SHLIB-${SDATA2}}
508  ${CREATE_SHLIB-${SBSS2}}
509  ${OTHER_READONLY_SECTIONS}
510  .eh_frame_hdr : { *(.eh_frame_hdr) }
511  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
512  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
513
514  /* Adjust the address for the data segment.  We want to adjust up to
515     the same address within the page on the next page up.  */
516  ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
517  ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
518  ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
519
520  /* Exception handling  */
521  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
522  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
523
524  /* Thread Local Storage sections  */
525  .tdata	${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
526  .tbss		${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
527
528  .preinit_array   ${RELOCATING-0} :
529  {
530    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_start = .);}}
531    KEEP (*(.preinit_array))
532    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);}}
533  } 
534  .init_array   ${RELOCATING-0} :
535  {
536     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);}}
537     KEEP (*(SORT(.init_array.*)))
538     KEEP (*(.init_array))
539     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);}}
540  }  
541  .fini_array   ${RELOCATING-0} :
542  {
543    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);}}
544    KEEP (*(.fini_array))
545    KEEP (*(SORT(.fini_array.*)))
546    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);}}
547  } 
548  ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
549  ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}
550  .jcr          ${RELOCATING-0} : { KEEP (*(.jcr)) }
551
552  ${RELOCATING+${DATARELRO}}
553  ${OTHER_RELRO_SECTIONS}
554  ${TEXT_DYNAMIC-${DYNAMIC}}
555  ${DATA_GOT+${RELRO_NOW+${GOT}}}
556  ${DATA_GOT+${RELRO_NOW+${GOTPLT}}}
557  ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT+${GOT}}}}
558  ${RELOCATING+${DATA_SEGMENT_RELRO_END}}
559  ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT-${GOT}}}}
560  ${DATA_GOT+${RELRO_NOW-${GOTPLT}}}
561
562  ${DATA_PLT+${PLT_BEFORE_GOT-${PLT}}}
563
564  .data ${RELOCATING+ADDR(.dtors)+SIZEOF(.dtors)} ${RELOCATING-0} :
565  {
566    ${RELOCATING+${DATA_START_SYMBOLS}}
567    *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
568    ${CONSTRUCTING+SORT(CONSTRUCTORS)}
569  }  /*> INTERNAL_RAM*/
570  .data1        ${RELOCATING-0} : { *(.data1) }  
571  ${WRITABLE_RODATA+${RODATA}}
572  ${OTHER_READWRITE_SECTIONS}
573  ${SMALL_DATA_CTOR+${RELOCATING+${CTOR}}}
574  ${SMALL_DATA_DTOR+${RELOCATING+${DTOR}}}
575  ${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}
576  ${SDATA_GOT+${RELOCATING+${OTHER_GOT_SYMBOLS}}}
577  ${SDATA_GOT+${GOT}}
578  ${SDATA_GOT+${OTHER_GOT_SECTIONS}}
579  ${SDATA}
580  ${OTHER_SDATA_SECTIONS}
581  ${RELOCATING+${DATA_END_SYMBOLS-${USER_LABEL_PREFIX}_edata = .; PROVIDE (${USER_LABEL_PREFIX}edata = .);}}
582  /* Align ___bss_start and _end to a multiple of 8 so that we can use strd
583     to clear bss.  N.B., without adding any extra alignment, we would have
584     to clear the bss byte by byte.  */
585  ${RELOCATING+. = ALIGN(8);}
586  ${RELOCATING+___bss_start = .;}
587  ${RELOCATING+${OTHER_BSS_SYMBOLS}}
588  ${SBSS}
589  ${BSS_PLT+${PLT}}
590  .bss ${RELOCATING+ADDR(.rodata)+SIZEOF(.rodata)} ${RELOCATING-0} :
591  {
592   *(.dynbss)
593   *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
594   *(COMMON)
595   /* Align here to ensure that the .bss section occupies space up to
596      _end.  Align after .bss to ensure correct alignment even if the
597      .bss section disappears because there are no input sections.
598      FIXME: Why do we need it? When there is no .bss section, we don't
599      pad the .data section.  */
600   ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
601  }  /*> INTERNAL_RAM*/
602  ${OTHER_BSS_SECTIONS}
603  ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
604  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
605  ${LARGE_SECTIONS}
606  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
607  ${RELOCATING+. = ALIGN(8);}
608  ${RELOCATING+${OTHER_END_SYMBOLS}}
609  ${RELOCATING+${END_SYMBOLS-${USER_LABEL_PREFIX}_end = .; PROVIDE (${USER_LABEL_PREFIX}end = .);}}
610  ${RELOCATING+${DATA_SEGMENT_END}}
611EOF
612
613if test -n "${NON_ALLOC_DYN}"; then
614  if test -z "${NO_REL_RELOCS}${NO_RELA_RELOCS}"; then
615    cat ldscripts/dyntmp.$$
616  else
617    if test -z "${NO_REL_RELOCS}"; then
618      sed -e '/^[ 	]*\.rela\.[^}]*$/,/}/d' -e '/^[ 	]*\.rela\./d' ldscripts/dyntmp.$$
619    fi
620    if test -z "${NO_RELA_RELOCS}"; then
621      sed -e '/^[ 	]*\.rel\.[^}]*$/,/}/d' -e '/^[ 	]*\.rel\./d' ldscripts/dyntmp.$$
622    fi
623  fi
624  rm -f ldscripts/dyntmp.$$
625fi
626
627cat <<EOF
628  /* Stabs debugging sections.  */
629  .stab          0 : { *(.stab) }
630  .stabstr       0 : { *(.stabstr) }
631  .stab.excl     0 : { *(.stab.excl) }
632  .stab.exclstr  0 : { *(.stab.exclstr) }
633  .stab.index    0 : { *(.stab.index) }
634  .stab.indexstr 0 : { *(.stab.indexstr) }
635
636  .comment       0 : { *(.comment) }
637
638EOF
639
640. $srcdir/scripttempl/DWARF.sc
641
642cat <<EOF
643  ${TINY_DATA_SECTION}
644  ${TINY_BSS_SECTION}
645
646  /*${STACK_ADDR+${STACK}}*/
647  
648  PROVIDE ( __stack_start_ = ORIGIN(EXTERNAL_DRAM_0) + __PROG_SIZE_FOR_CORE__ * __CORE_NUM_ + __PROG_SIZE_FOR_CORE__  - 0x10) ;
649  .stack ${RELOCATING+__stack_start_} :  {    ___stack = .;    *(.stack)  }
650
651  PROVIDE (  ___heap_start = ORIGIN(EXTERNAL_DRAM_1)  + __HEAP_SIZE_FOR_CORE__ * __CORE_NUM_ );
652  /*.heap_start      __heap_start_    :  {    _heap_start_ = .;    *(.heap_start)  }*/
653
654  PROVIDE (  ___heap_end =   ORIGIN(EXTERNAL_DRAM_1)  + __HEAP_SIZE_FOR_CORE__ * __CORE_NUM_  + __HEAP_SIZE_FOR_CORE__ - 4 );
655  
656  
657 /* .heap_end      __heap_end_    :  {    _heap_end_ = .;    *(.heap_end)  }*/
658
659
660  ${ATTRS_SECTIONS}
661  ${OTHER_SECTIONS}
662  ${RELOCATING+${OTHER_SYMBOLS}}
663  ${RELOCATING+${DISCARDED}}
664}
665EOF
666