1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * (C) Copyright 2007 Tensilica, Inc.
4  * (C) Copyright 2014 - 2016 Cadence Design Systems Inc.
5  */
6 
7 #ifndef _XTENSA_LDSCRIPT_H
8 #define _XTENSA_LDSCRIPT_H
9 
10 /*
11  * This linker script is pre-processed with CPP to avoid hard-coding
12  * addresses that depend on the Xtensa core configuration, because
13  * this FPGA board can be used with a huge variety of Xtensa cores.
14  */
15 
16 #include <asm/arch/core.h>
17 #include <asm/addrspace.h>
18 
19 #define ALIGN_LMA	4
20 #define LMA_EQ_VMA
21 #define FORCE_OUTPUT	. = .
22 #define FOLLOWING(sec)							\
23 	AT(((LOADADDR(sec) + SIZEOF(sec) + ALIGN_LMA-1)) & ~(ALIGN_LMA-1))
24 
25 /*
26  * Specify an output section that will be added to the ROM store table
27  * (PACKED_SECTION) or one that will be resident in ROM (RESIDENT_SECTION).
28  * 'symname' is a base name for section boundary symbols *_start & *_end.
29  * 'lma' is the load address at which a section will be packed in ROM.
30  * 'region' is the basename identifying a memory region and program header.
31  * 'keep' prevents removal of empty sections (must be 'KEEP' or 'NOKEEP').
32  */
33 
34 #define RELOCATE1(_sec_)						\
35 	LONG(_##_sec_##_start);						\
36 	LONG(_##_sec_##_end);						\
37 	LONG(LOADADDR(.##_sec_));
38 
39 #define RELOCATE2(_sym_, _sec_)						\
40 	LONG(_##_sym_##_##_sec_##_start);				\
41 	LONG(_##_sym_##_##_sec_##_end);					\
42 	LONG(LOADADDR(.##_sym_##.##_sec_));
43 
44 #define RELOCATE_USER1(_sec_)						\
45 	LONG(_##_sec_##_start);						\
46 	LONG(_##_sec_##_end);						\
47 	LONG(LOADADDR(_sec_));
48 
49 #define SECTION_VECTOR(_sym_, _sec_, _vma_, _lma_)			\
50 .##_sym_##.##_sec_ _vma_ : _lma_					\
51 {									\
52 	. = ALIGN(4);							\
53 	_##_sym_##_##_sec_##_start = ABSOLUTE(.);			\
54 	KEEP(*(.##_sym_##.##_sec_))					\
55 	_##_sym_##_##_sec_##_end = ABSOLUTE(.);				\
56 }
57 
58 /* In MMU configs there are two aliases of SYSROM, cached and uncached.
59  * For various reasons it is simpler to use the uncached mapping for load
60  * addresses, so ROM sections end up contiguous with the reset vector and
61  * we get a compact binary image. However we can gain performance by doing
62  * the unpacking from the cached ROM mapping. So we adjust all the load
63  * addresses in the ROM store table with an offset to the cached mapping,
64  * including the symbols referring to the ROM store table itself.
65  */
66 
67 #define SECTION_ResetVector(_vma_, _lma_)				\
68 	.ResetVector.text _vma_ : _lma_					\
69 	{								\
70 		FORCE_OUTPUT;						\
71 		KEEP(*(.ResetVector.text));				\
72 		KEEP(*(.reset.literal .reset.text))			\
73 	}
74 
75 #define SECTION_text(_vma_, _lma_)					\
76 	.text _vma_ : _lma_						\
77 	{								\
78 		_text_start = ABSOLUTE(.);				\
79 		*(.literal .text)					\
80 		*(.literal.* .text.* .stub)				\
81 		*(.gnu.warning .gnu.linkonce.literal.*)			\
82 		*(.gnu.linkonce.t.*.literal .gnu.linkonce.t.*)		\
83 		*(.fini.literal)					\
84 		*(.fini)						\
85 		*(.gnu.version)						\
86 		_text_end = ABSOLUTE(.);				\
87 	}
88 
89 #define SECTION_rodata(_vma_, _lma_)					\
90 	.rodata _vma_ : _lma_						\
91 	{								\
92 		_rodata_start = ABSOLUTE(.);				\
93 		*(.rodata)						\
94 		*(.rodata.*)						\
95 		*(.dtb.init.rodata)					\
96 		*(.gnu.linkonce.r.*)					\
97 		*(.rodata1)						\
98 		__XT_EXCEPTION_TABLE__ = ABSOLUTE(.);			\
99 		*(.xt_except_table)					\
100 		*(.gcc_except_table)					\
101 		*(.gnu.linkonce.e.*)					\
102 		*(.gnu.version_r)					\
103 		. = ALIGN(16);						\
104 		 _rodata_end = ABSOLUTE(.);				\
105 	}
106 
107 #define SECTION_u_boot_list(_vma_, _lma_)				\
108 	__u_boot_list _vma_ : _lma_					\
109 	{								\
110 		___u_boot_list_start = ABSOLUTE(.);			\
111 		KEEP(*(SORT(__u_boot_list*)));				\
112 		___u_boot_list_end = ABSOLUTE(.);			\
113 	}
114 
115 #define SECTION_data(_vma_, _lma_)					\
116 	.data _vma_ : _lma_						\
117 	{								\
118 		_data_start = ABSOLUTE(.);				\
119 		*(.data)						\
120 		*(.data.*)						\
121 		*(.gnu.linkonce.d.*)					\
122 		*(.data1)						\
123 		*(.sdata)						\
124 		*(.sdata.*)						\
125 		*(.gnu.linkonce.s.*)					\
126 		*(.sdata2)						\
127 		*(.sdata2.*)						\
128 		*(.gnu.linkonce.s2.*)					\
129 		*(.jcr)							\
130 		*(.eh_frame)						\
131 		*(.dynamic)						\
132 		*(.gnu.version_d)					\
133 		_data_end = ABSOLUTE(.);				\
134 	}
135 
136 #define SECTION_lit4(_vma_, _lma_)					\
137 	.lit4 _vma_ : _lma_						\
138 	{								\
139 		_lit4_start = ABSOLUTE(.);				\
140 		*(*.lit4)						\
141 		*(.gnu.linkonce.lit4.*)					\
142 		_lit4_end = ABSOLUTE(.);				\
143 	}
144 
145 #define SECTION_bss(_vma_, _lma_)					\
146 	.bss _vma_ : _lma_						\
147 	{								\
148 		. = ALIGN(8);						\
149 		_bss_start = ABSOLUTE(.);				\
150 		__bss_start = ABSOLUTE(.);				\
151 		*(.dynsbss)						\
152 		*(.sbss)						\
153 		*(.sbss.*)						\
154 		*(.gnu.linkonce.sb.*)					\
155 		*(.scommon)						\
156 		*(.sbss2)						\
157 		*(.sbss2.*)						\
158 		*(.gnu.linkonce.sb2.*)					\
159 		*(.dynbss)						\
160 		*(.bss)							\
161 		*(.bss.*)						\
162 		*(.gnu.linkonce.b.*)					\
163 		*(COMMON)						\
164 		*(.sram.bss)						\
165 		. = ALIGN(8);						\
166 		_bss_end = ABSOLUTE(.);					\
167 		__bss_end = ABSOLUTE(.);				\
168 		_end = ALIGN(0x8);					\
169 		PROVIDE(end = ALIGN(0x8));				\
170 		_stack_sentry = ALIGN(0x8);				\
171 	}
172 
173 #define SECTION_debug							\
174 	.debug           0 :  { *(.debug) }				\
175 	.line            0 :  { *(.line) }				\
176 	.debug_srcinfo   0 :  { *(.debug_srcinfo) }			\
177 	.debug_sfnames   0 :  { *(.debug_sfnames) }			\
178 	.debug_aranges   0 :  { *(.debug_aranges) }			\
179 	.debug_pubnames  0 :  { *(.debug_pubnames) }			\
180 	.debug_info      0 :  { *(.debug_info) }			\
181 	.debug_abbrev    0 :  { *(.debug_abbrev) }			\
182 	.debug_line      0 :  { *(.debug_line) }			\
183 	.debug_frame     0 :  { *(.debug_frame) }			\
184 	.debug_str       0 :  { *(.debug_str) }				\
185 	.debug_loc       0 :  { *(.debug_loc) }				\
186 	.debug_macinfo   0 :  { *(.debug_macinfo) }			\
187 	.debug_weaknames 0 :  { *(.debug_weaknames) }			\
188 	.debug_funcnames 0 :  { *(.debug_funcnames) }			\
189 	.debug_typenames 0 :  { *(.debug_typenames) }			\
190 	.debug_varnames  0 :  { *(.debug_varnames) }
191 
192 #define SECTION_xtensa							\
193 	.xt.insn 0 :							\
194 	{								\
195 		KEEP (*(.xt.insn))					\
196 		KEEP (*(.gnu.linkonce.x.*))				\
197 	}								\
198 	.xt.prop 0 :							\
199 	{								\
200 		KEEP (*(.xt.prop))					\
201 		KEEP (*(.xt.prop.*))					\
202 		KEEP (*(.gnu.linkonce.prop.*))				\
203 	}								\
204 	.xt.lit 0 :							\
205 	{								\
206 		KEEP (*(.xt.lit))					\
207 		KEEP (*(.xt.lit.*))					\
208 		KEEP (*(.gnu.linkonce.p.*))				\
209 	}								\
210 	.xt.profile_range 0 :						\
211 	{								\
212 		KEEP (*(.xt.profile_range))				\
213 		KEEP (*(.gnu.linkonce.profile_range.*))			\
214 	}								\
215 	.xt.profile_ranges 0 :						\
216 	{								\
217 		KEEP (*(.xt.profile_ranges))				\
218 		KEEP (*(.gnu.linkonce.xt.profile_ranges.*))		\
219 	}								\
220 	.xt.profile_files 0 :						\
221 	{								\
222 		KEEP (*(.xt.profile_files))				\
223 		KEEP (*(.gnu.linkonce.xt.profile_files.*))		\
224 	}
225 
226 #endif	/* _XTENSA_LDSCRIPT_H */
227