xref: /optee_os/core/arch/arm/kernel/kern.ld.S (revision a4f139d7fc30f5de9b7cd822b83495b22597fd5b)
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#ifdef CFG_DT
96		__rodata_dtdrv_start = .;
97		KEEP(*(.rodata.dtdrv))
98		__rodata_dtdrv_end = .;
99#endif
100		*(.rodata .rodata.*)
101
102		/*
103		 * 8 to avoid unwanted padding between __start_ta_head_section
104		 * and the first structure in ta_head_section, in 64-bit
105		 * builds
106		 */
107		. = ALIGN(8);
108		__start_ta_head_section = . ;
109		KEEP(*(ta_head_section))
110		__stop_ta_head_section = . ;
111		. = ALIGN(8);
112		__start_phys_mem_map_section = . ;
113		KEEP(*(phys_mem_map_section))
114		__end_phys_mem_map_section = . ;
115		. = ALIGN(8);
116		__start_phys_sdp_mem_section = . ;
117		KEEP(*(phys_sdp_mem_section))
118		__end_phys_sdp_mem_section = . ;
119#endif
120		. = ALIGN(8);
121		__rodata_end = .;
122	}
123
124	.interp : { *(.interp) }
125	.hash : { *(.hash) }
126	.dynsym : { *(.dynsym) }
127	.dynstr : { *(.dynstr) }
128	.rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) }
129	.rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) }
130	.rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) }
131	.rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) }
132	.rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
133	.rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
134	.rel.got : { *(.rel.got) }
135	.rela.got : { *(.rela.got) }
136	.rel.ctors : { *(.rel.ctors) }
137	.rela.ctors : { *(.rela.ctors) }
138	.rel.dtors : { *(.rel.dtors) }
139	.rela.dtors : { *(.rela.dtors) }
140	.rel.init : { *(.rel.init) }
141	.rela.init : { *(.rela.init) }
142	.rel.fini : { *(.rel.fini) }
143	.rela.fini : { *(.rela.fini) }
144	.rel.bss : { *(.rel.bss) }
145	.rela.bss : { *(.rela.bss) }
146	.rel.plt : { *(.rel.plt) }
147	.rela.plt : { *(.rela.plt) }
148	.init : { *(.init) } =0x9090
149	.plt : { *(.plt) }
150
151	/* .ARM.exidx is sorted, so has to go in its own output section.  */
152	.ARM.exidx : {
153		__exidx_start = .;
154		*(.ARM.exidx* .gnu.linkonce.armexidx.*)
155		__exidx_end = .;
156	}
157
158	.ARM.extab : {
159		__extab_start = .;
160		*(.ARM.extab*)
161		__extab_end = .;
162	}
163
164	.data : ALIGN(8) {
165		/* writable data  */
166		__data_start_rom = .;
167		/* in one segment binaries, the rom data address is on top
168		   of the ram data address */
169		__early_bss_start = .;
170		*(.early_bss .early_bss.*)
171		. = ALIGN(8);
172		__early_bss_end = .;
173		__data_start = .;
174		*(.data .data.* .gnu.linkonce.d.*)
175		. = ALIGN(8);
176	}
177
178	.ctors : ALIGN(8) {
179		__ctor_list = .;
180		KEEP(*(.ctors .ctors.* .init_array .init_array.*))
181		__ctor_end = .;
182	}
183	.dtors : ALIGN(8) {
184		__dtor_list = .;
185		KEEP(*(.dtors .dtors.* .fini_array .fini_array.*))
186		__dtor_end = .;
187	}
188	.got : { *(.got.plt) *(.got) }
189	.dynamic : { *(.dynamic) }
190
191	__data_end = .;
192	/* unintialized data */
193	.bss : ALIGN(8) {
194		__bss_start = .;
195		*(.bss .bss.*)
196		*(.gnu.linkonce.b.*)
197		*(COMMON)
198		. = ALIGN(8);
199		__bss_end = .;
200	}
201
202	.heap1 (NOLOAD) : {
203		/*
204		 * We're keeping track of the padding added before the
205		 * .nozi section so we can do something useful with
206		 * this otherwise wasted memory.
207		 */
208		__heap1_start = .;
209#ifndef CFG_WITH_PAGER
210		. += CFG_CORE_HEAP_SIZE;
211#endif
212		. = ALIGN(16 * 1024);
213		__heap1_end = .;
214	}
215
216	/*
217	 * Uninitialized data that shouldn't be zero initialized at
218	 * runtime.
219	 *
220	 * L1 mmu table requires 16 KiB alignment
221	 */
222	.nozi (NOLOAD) : ALIGN(16 * 1024) {
223		__nozi_start = .;
224		KEEP(*(.nozi .nozi.*))
225		. = ALIGN(16);
226		__nozi_end = .;
227		__nozi_stack_start = .;
228		KEEP(*(.nozi_stack))
229		. = ALIGN(8);
230		__nozi_stack_end = .;
231	}
232
233#ifdef CFG_WITH_PAGER
234	.heap2 (NOLOAD) : {
235		__heap2_start = .;
236		/*
237		 * Reserve additional memory for heap, the total should be
238		 * at least CFG_CORE_HEAP_SIZE, but count what has already
239		 * been reserved in .heap1
240		 */
241		. += CFG_CORE_HEAP_SIZE - (__heap1_end - __heap1_start);
242		. = ALIGN(4 * 1024);
243		__heap2_end = .;
244	}
245
246	.text_init : ALIGN(4 * 1024) {
247		__text_init_start = .;
248/*
249 * Include list of sections needed for boot initialization, this list
250 * overlaps with unpaged.ld.S but since unpaged.ld.S is first all those
251 * sections will go into the unpaged area.
252 */
253#include <text_init.ld.S>
254		. = ALIGN(8);
255		__text_init_end = .;
256	}
257
258	.rodata_init : ALIGN(8) {
259		__rodata_init_start = .;
260#include <rodata_init.ld.S>
261		. = ALIGN(8);
262		__start_phys_mem_map_section = . ;
263		KEEP(*(phys_mem_map_section))
264		__end_phys_mem_map_section = . ;
265		. = ALIGN(8);
266		__start_phys_sdp_mem_section = . ;
267		KEEP(*(phys_sdp_mem_section))
268		__end_phys_sdp_mem_section = . ;
269		. = ALIGN(8);
270		__rodata_init_end = .;
271	}
272	__init_start = __text_init_start;
273	__init_end = .;
274	__init_size = __init_end - __text_init_start;
275
276	.text_pageable : ALIGN(8) {
277		__text_pageable_start = .;
278		*(.text*)
279		. = ALIGN(8);
280		__text_pageable_end = .;
281	}
282
283	.rodata_pageable : ALIGN(8) {
284		__rodata_pageable_start = .;
285#ifdef CFG_DT
286		__rodata_dtdrv_start = .;
287		KEEP(*(.rodata.dtdrv))
288		__rodata_dtdrv_end = .;
289#endif
290		*(.rodata*)
291		/*
292		 * 8 to avoid unwanted padding between __start_ta_head_section
293		 * and the first structure in ta_head_section, in 64-bit
294		 * builds
295		 */
296		. = ALIGN(8);
297		__start_ta_head_section = . ;
298		KEEP(*(ta_head_section))
299		__stop_ta_head_section = . ;
300		. = ALIGN(4 * 1024);
301		__rodata_pageable_end = .;
302	}
303
304	__pageable_part_start = __rodata_init_end;
305	__pageable_part_end = __rodata_pageable_end;
306	__pageable_start = __text_init_start;
307	__pageable_end = __pageable_part_end;
308
309	/*
310	 * Assign a safe spot to store the hashes of the pages before
311	 * heap is initialized.
312	 */
313	__tmp_hashes_start = __rodata_init_end;
314	__tmp_hashes_size = ((__pageable_end - __pageable_start) /
315				(4 * 1024)) * 32;
316	__tmp_hashes_end = __tmp_hashes_start + __tmp_hashes_size;
317
318	__init_mem_usage = __tmp_hashes_end - CFG_TEE_LOAD_ADDR;
319
320	ASSERT(CFG_TEE_LOAD_ADDR >= CFG_TEE_RAM_START,
321		"Load address before start of physical memory")
322	ASSERT(CFG_TEE_LOAD_ADDR < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
323		"Load address after end of physical memory")
324	ASSERT(__tmp_hashes_end < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
325		"OP-TEE can't fit init part into available physical memory")
326	ASSERT((CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE - __init_end) >
327		1 * 4096, "Too few free pages to initialize paging")
328
329
330#endif /*CFG_WITH_PAGER*/
331
332#ifdef CFG_CORE_SANITIZE_KADDRESS
333	. = CFG_TEE_RAM_START + (CFG_TEE_RAM_VA_SIZE * 8) / 9 - 8;
334	. = ALIGN(8);
335	.asan_shadow : {
336		__asan_shadow_start = .;
337		. += CFG_TEE_RAM_VA_SIZE / 9;
338		__asan_shadow_end = .;
339	}
340#endif /*CFG_CORE_SANITIZE_KADDRESS*/
341
342	__end = .;
343
344#ifndef CFG_WITH_PAGER
345	__init_size = __data_end - CFG_TEE_LOAD_ADDR;
346	__init_mem_usage = __end - CFG_TEE_LOAD_ADDR;
347#endif
348	. = CFG_TEE_RAM_START + CFG_TEE_RAM_VA_SIZE;
349	_end_of_ram = .;
350
351	/DISCARD/ : {
352		/* Strip unnecessary stuff */
353		*(.comment .note .eh_frame)
354		/* Strip meta variables */
355		*(__keep_meta_vars*)
356	}
357
358}
359