1# Linker Script for National Semiconductor's CR16-ELF32.
2#
3# Copyright (C) 2014-2017 Free Software Foundation, Inc.
4# 
5# Copying and distribution of this file, with or without modification,
6# are permitted in any medium without royalty provided the copyright
7# notice and this notice are preserved.
8
9# The next line should be uncommented if it is desired to link
10# without libstart.o and directly enter main.
11
12# ENTRY=_main
13
14test -z "$ENTRY" && ENTRY=_start
15cat <<EOF
16
17/* Example Linker Script for linking NS CR16 elf32 files.
18   Copyright (C) 2014-2017 Free Software Foundation, Inc.
19
20   Copying and distribution of this script, with or without modification,
21   are permitted in any medium without royalty provided the copyright
22   notice and this notice are preserved.  */
23
24OUTPUT_FORMAT("${OUTPUT_FORMAT}")
25OUTPUT_ARCH(${ARCH})
26${RELOCATING+ENTRY(${ENTRY})}
27
28/* Define memory regions.  */
29MEMORY
30{
31        rom         : ORIGIN = 0x2,         LENGTH = 3M
32        ram         : ORIGIN = 4M,          LENGTH = 10M
33}
34
35/*  Many sections come in three flavours.  There is the 'real' section,
36    like ".data".  Then there are the per-procedure or per-variable
37    sections, generated by -ffunction-sections and -fdata-sections in GCC,
38    and useful for --gc-sections, which for a variable "foo" might be
39    ".data.foo".  Then there are the linkonce sections, for which the linker
40    eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
41    The exact correspondences are:
42
43    Section	Linkonce section
44    .text	.gnu.linkonce.t.foo
45    .rdata	.gnu.linkonce.r.foo
46    .data	.gnu.linkonce.d.foo
47    .bss	.gnu.linkonce.b.foo
48    .debug_info	.gnu.linkonce.wi.foo  */
49
50SECTIONS
51{
52  .init :
53  { 
54    __INIT_START = .; 
55    KEEP (*(.init))
56    __INIT_END = .; 
57  } > rom
58
59  .fini :
60  { 
61    __FINI_START = .; 
62    KEEP (*(.fini))
63    __FINI_END = .; 
64  } > rom
65
66  .jcr :
67  { 
68    KEEP (*(.jcr))
69  } > rom
70
71  .text : 
72  {
73    __TEXT_START = .;
74    *(.text) *(.text.*) *(.gnu.linkonce.t.*)
75    __TEXT_END = .;
76  } > rom
77
78  .rdata :
79  {
80    __RDATA_START = .;
81    *(.rdata_4) *(.rdata_2) *(.rdata_1) *(.rdata.*) *(.gnu.linkonce.r.*) *(.rodata*)
82    __RDATA_END = .;
83  } > rom
84
85  .ctor ALIGN(4) : 
86  { 
87    __CTOR_START = .; 
88    /* The compiler uses crtbegin.o to find the start
89       of the constructors, so we make sure it is
90       first.  Because this is a wildcard, it
91       doesn't matter if the user does not
92       actually link against crtbegin.o; the
93       linker won't look for a file to match a
94       wildcard.  The wildcard also means that it
95       doesn't matter which directory crtbegin.o
96       is in.  */
97
98    KEEP (*crtbegin*.o(.ctors))
99
100    /* We don't want to include the .ctor section from
101       the crtend.o file until after the sorted ctors.
102       The .ctor section from the crtend file contains the
103       end of ctors marker and it must be last */
104
105    KEEP (*(EXCLUDE_FILE (*crtend*.o) .ctors))
106    KEEP (*(SORT(.ctors.*)))
107    KEEP (*(.ctors))
108    __CTOR_END = .; 
109  } > rom
110
111  .dtor ALIGN(4) : 
112  { 
113    __DTOR_START = .; 
114    KEEP (*crtbegin*.o(.dtors))
115    KEEP (*(EXCLUDE_FILE (*crtend*.o) .dtors))
116    KEEP (*(SORT(.dtors.*)))
117    KEEP (*(.dtors))
118    __DTOR_END = .; 
119  } > rom
120
121  .data :
122  {
123    __DATA_START = .;
124    *(.data_4) *(.data_2) *(.data_1) *(.data) *(.data.*) *(.gnu.linkonce.d.*)
125    __DATA_END = .;
126  } > ram AT > rom
127
128  .bss (NOLOAD) :
129  {
130    __BSS_START = .;
131    *(.bss_4) *(.bss_2) *(.bss_1) *(.bss) *(COMMON) *(.bss.*) *(.gnu.linkonce.b.*)
132    __BSS_END = .;
133  } > ram
134
135/* You may change the sizes of the following sections to fit the actual
136   size your program requires.
137
138   The heap and stack are aligned to the bus width, as a speed optimization
139   for accessing data located there.  */
140
141  .heap (NOLOAD) :
142  {
143    . = ALIGN(4);
144    __HEAP_START = .;
145    . += 0x2000; __HEAP_MAX = .;
146  } > ram
147
148  .stack (NOLOAD) :
149  {
150    . = ALIGN(4);
151    . += 0x6000;
152    __STACK_START = .;
153  } > ram
154
155  .istack (NOLOAD) :
156  {
157    . = ALIGN(4);
158    . += 0x100;
159    __ISTACK_START = .;
160  } > ram
161
162  .comment        0 : { *(.comment) }
163
164EOF
165
166. $srcdir/scripttempl/DWARF.sc
167
168cat <<EOF
169}
170
171__DATA_IMAGE_START = LOADADDR(.data);
172EOF
173