xref: /optee_os/core/arch/arm/kernel/kern.ld.S (revision 40ea51dee3aa8ae6f07ff8bf1299bfe7799a4db5)
1/*
2 * Copyright (c) 2014, Linaro Limited
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/*
29 * Copyright (c) 2008-2010 Travis Geiselbrecht
30 *
31 * Permission is hereby granted, free of charge, to any person obtaining
32 * a copy of this software and associated documentation files
33 * (the "Software"), to deal in the Software without restriction,
34 * including without limitation the rights to use, copy, modify, merge,
35 * publish, distribute, sublicense, and/or sell copies of the Software,
36 * and to permit persons to whom the Software is furnished to do so,
37 * subject to the following conditions:
38 *
39 * The above copyright notice and this permission notice shall be
40 * included in all copies or substantial portions of the Software.
41 *
42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49 */
50
51#include <platform_config.h>
52
53OUTPUT_FORMAT(CFG_KERN_LINKER_FORMAT)
54OUTPUT_ARCH(CFG_KERN_LINKER_ARCH)
55
56ENTRY(_start)
57SECTIONS
58{
59	. = CFG_TEE_LOAD_ADDR;
60
61	/* text/read-only data */
62	.text : {
63		__text_start = .;
64		KEEP(*(.text.boot.vectab1))
65		KEEP(*(.text.boot.vectab2))
66		KEEP(*(.text.boot))
67
68		. = ALIGN(8);
69		__initcall_start = .;
70		KEEP(*(.initcall1))
71		KEEP(*(.initcall2))
72		KEEP(*(.initcall3))
73		KEEP(*(.initcall4))
74		__initcall_end = .;
75
76#ifdef CFG_WITH_PAGER
77		*(.text)
78/* Include list of sections needed for paging */
79#include <text_unpaged.ld.S>
80#else
81		*(.text .text.*)
82#endif
83		*(.sram.text.glue_7* .gnu.linkonce.t.*)
84		. = ALIGN(8);
85		__text_end = .;
86	}
87
88	.rodata : ALIGN(8) {
89		__rodata_start = .;
90		*(.gnu.linkonce.r.*)
91#ifdef CFG_WITH_PAGER
92		*(.rodata .rodata.__unpaged)
93#include <rodata_unpaged.ld.S>
94#else
95		*(.rodata .rodata.*)
96
97		/*
98		 * 8 to avoid unwanted padding between __start_ta_head_section
99		 * and the first structure in ta_head_section, in 64-bit
100		 * builds
101		 */
102		. = ALIGN(8);
103		__start_ta_head_section = . ;
104		KEEP(*(ta_head_section))
105		__stop_ta_head_section = . ;
106		. = ALIGN(8);
107		__start_phys_mem_map_section = . ;
108		KEEP(*(phys_mem_map_section))
109		__end_phys_mem_map_section = . ;
110		. = ALIGN(8);
111		__start_phys_sdp_mem_section = . ;
112		KEEP(*(phys_sdp_mem_section))
113		__end_phys_sdp_mem_section = . ;
114#endif
115		. = ALIGN(8);
116		__rodata_end = .;
117	}
118
119	.interp : { *(.interp) }
120	.hash : { *(.hash) }
121	.dynsym : { *(.dynsym) }
122	.dynstr : { *(.dynstr) }
123	.rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) }
124	.rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) }
125	.rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) }
126	.rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) }
127	.rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
128	.rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
129	.rel.got : { *(.rel.got) }
130	.rela.got : { *(.rela.got) }
131	.rel.ctors : { *(.rel.ctors) }
132	.rela.ctors : { *(.rela.ctors) }
133	.rel.dtors : { *(.rel.dtors) }
134	.rela.dtors : { *(.rela.dtors) }
135	.rel.init : { *(.rel.init) }
136	.rela.init : { *(.rela.init) }
137	.rel.fini : { *(.rel.fini) }
138	.rela.fini : { *(.rela.fini) }
139	.rel.bss : { *(.rel.bss) }
140	.rela.bss : { *(.rela.bss) }
141	.rel.plt : { *(.rel.plt) }
142	.rela.plt : { *(.rela.plt) }
143	.init : { *(.init) } =0x9090
144	.plt : { *(.plt) }
145
146	/* .ARM.exidx is sorted, so has to go in its own output section.  */
147	.ARM.exidx : {
148		__exidx_start = .;
149		*(.ARM.exidx* .gnu.linkonce.armexidx.*)
150		__exidx_end = .;
151	}
152
153	.ARM.extab : {
154		__extab_start = .;
155		*(.ARM.extab*)
156		__extab_end = .;
157	}
158
159	.data : ALIGN(8) {
160		/* writable data  */
161		__data_start_rom = .;
162		/* in one segment binaries, the rom data address is on top
163		   of the ram data address */
164		__early_bss_start = .;
165		*(.early_bss .early_bss.*)
166		. = ALIGN(8);
167		__early_bss_end = .;
168		__data_start = .;
169		*(.data .data.* .gnu.linkonce.d.*)
170		. = ALIGN(8);
171	}
172
173	.ctors : ALIGN(8) {
174		__ctor_list = .;
175		KEEP(*(.ctors .ctors.* .init_array .init_array.*))
176		__ctor_end = .;
177	}
178	.dtors : ALIGN(8) {
179		__dtor_list = .;
180		KEEP(*(.dtors .dtors.* .fini_array .fini_array.*))
181		__dtor_end = .;
182	}
183	.got : { *(.got.plt) *(.got) }
184	.dynamic : { *(.dynamic) }
185
186	__data_end = .;
187	/* unintialized data */
188	.bss : ALIGN(8) {
189		__bss_start = .;
190		*(.bss .bss.*)
191		*(.gnu.linkonce.b.*)
192		*(COMMON)
193		. = ALIGN(8);
194		__bss_end = .;
195	}
196
197	.heap1 (NOLOAD) : {
198		/*
199		 * We're keeping track of the padding added before the
200		 * .nozi section so we can do something useful with
201		 * this otherwise wasted memory.
202		 */
203		__heap1_start = .;
204#ifndef CFG_WITH_PAGER
205		. += CFG_CORE_HEAP_SIZE;
206#endif
207		. = ALIGN(16 * 1024);
208		__heap1_end = .;
209	}
210
211	/*
212	 * Uninitialized data that shouldn't be zero initialized at
213	 * runtime.
214	 *
215	 * L1 mmu table requires 16 KiB alignment
216	 */
217	.nozi (NOLOAD) : ALIGN(16 * 1024) {
218		__nozi_start = .;
219		KEEP(*(.nozi .nozi.*))
220		. = ALIGN(16);
221		__nozi_end = .;
222		__nozi_stack_start = .;
223		KEEP(*(.nozi_stack))
224		. = ALIGN(8);
225		__nozi_stack_end = .;
226	}
227
228#ifdef CFG_WITH_PAGER
229	.heap2 (NOLOAD) : {
230		__heap2_start = .;
231		/*
232		 * Reserve additional memory for heap, the total should be
233		 * at least CFG_CORE_HEAP_SIZE, but count what has already
234		 * been reserved in .heap1
235		 */
236		. += CFG_CORE_HEAP_SIZE - (__heap1_end - __heap1_start);
237		. = ALIGN(4 * 1024);
238		__heap2_end = .;
239	}
240
241	.text_init : ALIGN(4 * 1024) {
242		__text_init_start = .;
243/*
244 * Include list of sections needed for boot initialization, this list
245 * overlaps with unpaged.ld.S but since unpaged.ld.S is first all those
246 * sections will go into the unpaged area.
247 */
248#include <text_init.ld.S>
249		. = ALIGN(8);
250		__text_init_end = .;
251	}
252
253	.rodata_init : ALIGN(8) {
254		__rodata_init_start = .;
255#include <rodata_init.ld.S>
256		. = ALIGN(8);
257		__start_phys_mem_map_section = . ;
258		KEEP(*(phys_mem_map_section))
259		__end_phys_mem_map_section = . ;
260		. = ALIGN(8);
261		__start_phys_sdp_mem_section = . ;
262		KEEP(*(phys_sdp_mem_section))
263		__end_phys_sdp_mem_section = . ;
264		. = ALIGN(8);
265		__rodata_init_end = .;
266	}
267	__init_start = __text_init_start;
268	__init_end = .;
269	__init_size = __init_end - __text_init_start;
270
271	.text_pageable : ALIGN(8) {
272		__text_pageable_start = .;
273		*(.text*)
274		. = ALIGN(8);
275		__text_pageable_end = .;
276	}
277
278	.rodata_pageable : ALIGN(8) {
279		__rodata_pageable_start = .;
280		*(.rodata*)
281		/*
282		 * 8 to avoid unwanted padding between __start_ta_head_section
283		 * and the first structure in ta_head_section, in 64-bit
284		 * builds
285		 */
286		. = ALIGN(8);
287		__start_ta_head_section = . ;
288		KEEP(*(ta_head_section))
289		__stop_ta_head_section = . ;
290		. = ALIGN(4 * 1024);
291		__rodata_pageable_end = .;
292	}
293
294	__pageable_part_start = __rodata_init_end;
295	__pageable_part_end = __rodata_pageable_end;
296	__pageable_start = __text_init_start;
297	__pageable_end = __pageable_part_end;
298
299	/*
300	 * Assign a safe spot to store the hashes of the pages before
301	 * heap is initialized.
302	 */
303	__tmp_hashes_start = __rodata_init_end;
304	__tmp_hashes_size = ((__pageable_end - __pageable_start) /
305				(4 * 1024)) * 32;
306	__tmp_hashes_end = __tmp_hashes_start + __tmp_hashes_size;
307
308	__init_mem_usage = __tmp_hashes_end - CFG_TEE_LOAD_ADDR;
309
310	ASSERT(CFG_TEE_LOAD_ADDR >= CFG_TEE_RAM_START,
311		"Load address before start of physical memory")
312	ASSERT(CFG_TEE_LOAD_ADDR < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
313		"Load address after end of physical memory")
314	ASSERT(__tmp_hashes_end < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
315		"OP-TEE can't fit init part into available physical memory")
316	ASSERT((CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE - __init_end) >
317		1 * 4096, "Too few free pages to initialize paging")
318
319
320#endif /*CFG_WITH_PAGER*/
321
322#ifdef CFG_CORE_SANITIZE_KADDRESS
323	. = CFG_TEE_RAM_START + (CFG_TEE_RAM_VA_SIZE * 8) / 9 - 8;
324	. = ALIGN(8);
325	.asan_shadow : {
326		__asan_shadow_start = .;
327		. += CFG_TEE_RAM_VA_SIZE / 9;
328		__asan_shadow_end = .;
329	}
330#endif /*CFG_CORE_SANITIZE_KADDRESS*/
331
332	__end = .;
333
334#ifndef CFG_WITH_PAGER
335	__init_size = __data_end - CFG_TEE_LOAD_ADDR;
336	__init_mem_usage = __end - CFG_TEE_LOAD_ADDR;
337#endif
338	. = CFG_TEE_RAM_START + CFG_TEE_RAM_VA_SIZE;
339	_end_of_ram = .;
340
341	/DISCARD/ : {
342		/* Strip unnecessary stuff */
343		*(.comment .note .eh_frame)
344		/* Strip meta variables */
345		*(__keep_meta_vars*)
346	}
347
348}
349