xref: /optee_os/core/arch/arm/kernel/kern.ld.S (revision 316a94e710afc8dcb5b6ac991741ac6370af65fc)
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(4);
69		__initcall_start = .;
70		KEEP(*(.initcall1))
71		KEEP(*(.initcall2))
72		__initcall_end = .;
73
74#ifdef CFG_WITH_PAGER
75		*(.text)
76/* Include list of sections needed for paging */
77#include <text_unpaged.ld.S>
78#else
79		*(.text .text.*)
80#endif
81		*(.sram.text.glue_7* .gnu.linkonce.t.*)
82		__text_end = .;
83	}
84
85	.interp : { *(.interp) }
86	.hash : { *(.hash) }
87	.dynsym : { *(.dynsym) }
88	.dynstr : { *(.dynstr) }
89	.rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) }
90	.rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) }
91	.rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) }
92	.rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) }
93	.rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
94	.rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
95	.rel.got : { *(.rel.got) }
96	.rela.got : { *(.rela.got) }
97	.rel.ctors : { *(.rel.ctors) }
98	.rela.ctors : { *(.rela.ctors) }
99	.rel.dtors : { *(.rel.dtors) }
100	.rela.dtors : { *(.rela.dtors) }
101	.rel.init : { *(.rel.init) }
102	.rela.init : { *(.rela.init) }
103	.rel.fini : { *(.rel.fini) }
104	.rela.fini : { *(.rela.fini) }
105	.rel.bss : { *(.rel.bss) }
106	.rela.bss : { *(.rela.bss) }
107	.rel.plt : { *(.rel.plt) }
108	.rela.plt : { *(.rela.plt) }
109	.init : { *(.init) } =0x9090
110	.plt : { *(.plt) }
111
112	/* .ARM.exidx is sorted, so has to go in its own output section.  */
113	.ARM.exidx : {
114		__exidx_start = .;
115		*(.ARM.exidx* .gnu.linkonce.armexidx.*)
116		__exidx_end = .;
117	}
118
119	.rodata : ALIGN(4) {
120		__rodata_start = .;
121		*(.gnu.linkonce.r.*)
122#ifdef CFG_WITH_PAGER
123		*(.rodata)
124#include <rodata_unpaged.ld.S>
125#else
126		*(.rodata .rodata.*)
127
128		. = ALIGN(4);
129		__start_ta_head_section = . ;
130		KEEP(*(ta_head_section))
131		__stop_ta_head_section = . ;
132#endif
133		. = ALIGN(4);
134		__rodata_end = .;
135	}
136
137
138	.data : ALIGN(4) {
139		/* writable data  */
140		__data_start_rom = .;
141		/* in one segment binaries, the rom data address is on top
142		   of the ram data address */
143		__data_start = .;
144		*(.data .data.* .gnu.linkonce.d.*)
145		. = ALIGN(4);
146	}
147
148	.ctors : ALIGN(4) {
149		__ctor_list = .;
150		*(.ctors)
151		__ctor_end = .;
152	}
153	.dtors : ALIGN(4) {
154		__dtor_list = .;
155		*(.dtors)
156		__dtor_end = .;
157	}
158	.got : { *(.got.plt) *(.got) }
159	.dynamic : { *(.dynamic) }
160
161	__data_end = .;
162	/* unintialized data */
163	.bss : ALIGN(4) {
164		__bss_start = .;
165		*(.bss .bss.*)
166		*(.gnu.linkonce.b.*)
167		*(COMMON)
168		. = ALIGN(4);
169		__bss_end = .;
170	}
171
172	.heap1 (NOLOAD) : {
173		/*
174		 * We're keeping track of the padding added before the
175		 * .nozi section so we can do something useful with
176		 * this otherwise wasted memory.
177		 */
178		__heap1_start = .;
179#ifndef CFG_WITH_PAGER
180		. += HEAP_SIZE;
181#endif
182		. = ALIGN(16 * 1024);
183		__heap1_end = .;
184	}
185
186	/*
187	 * Uninitialized data that shouldn't be zero initialized at
188	 * runtime.
189	 *
190	 * L1 mmu table requires 16 KiB alignment
191	 */
192	.nozi (NOLOAD) : ALIGN(16 * 1024) {
193		KEEP(*(.nozi .nozi.*))
194	}
195
196#ifdef CFG_WITH_PAGER
197	.heap2 (NOLOAD) : {
198		__heap2_start = .;
199		/*
200		 * Reserve additional memory for heap, the total should
201		 * be at least HEAP_SIZE, but count what has already been
202		 * reserved in .heap1
203		 */
204		. += HEAP_SIZE - (__heap1_end - __heap1_start);
205		. = ALIGN(4 * 1024);
206		__heap2_end = .;
207	}
208
209	.text_init : ALIGN(4 * 1024) {
210		__text_init_start = .;
211/*
212 * Include list of sections needed for boot initialization, this list
213 * overlaps with unpaged.ld.S but since unpaged.ld.S is first all those
214 * sections will go into the unpaged area.
215 */
216#include <text_init.ld.S>
217		. = ALIGN(4);
218		__text_init_end = .;
219	}
220
221	.rodata_init : ALIGN(4) {
222		__rodata_init_start = .;
223#include <rodata_init.ld.S>
224		. = ALIGN(4);
225		__rodata_init_end = .;
226	}
227	__init_start = __text_init_start;
228	__init_end = .;
229	__init_size = __init_end - __text_init_start;
230	__init_mem_usage = __init_end - CFG_TEE_LOAD_ADDR;
231
232	.text_pageable : ALIGN(4) {
233		__text_pageable_start = .;
234		*(.text*)
235		. = ALIGN(4);
236		__text_pageable_end = .;
237	}
238
239	.rodata_pageable : ALIGN(4) {
240		__rodata_pageable_start = .;
241		*(.rodata*)
242		. = ALIGN(4);
243		__start_ta_head_section = . ;
244		KEEP(*(ta_head_section))
245		__stop_ta_head_section = . ;
246		. = ALIGN(4 * 1024);
247		__rodata_pageable_end = .;
248	}
249
250	__pageable_part_start = __rodata_init_end;
251	__pageable_part_end = __rodata_pageable_end;
252	__pageable_start = __text_init_start;
253	__pageable_end = __pageable_part_end;
254
255	ASSERT(CFG_TEE_LOAD_ADDR >= CFG_TEE_RAM_START,
256		"Load address before start of physical memory")
257	ASSERT(CFG_TEE_LOAD_ADDR < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
258		"Load address after end of physical memory")
259	ASSERT(__init_end < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
260		"OP-TEE can't fit init part into available physical memory")
261	ASSERT((CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE - __init_end) >
262		1 * 4096, "Too few free pages to initialize paging")
263
264
265#endif /*CFG_WITH_PAGER*/
266
267	_end = .;
268
269#ifndef CFG_WITH_PAGER
270	__init_size = __data_end - CFG_TEE_LOAD_ADDR;
271	__init_mem_usage = _end - CFG_TEE_LOAD_ADDR;
272#endif
273	. = CFG_TEE_RAM_START + CFG_TEE_RAM_VA_SIZE;
274	_end_of_ram = .;
275
276	/* Strip unnecessary stuff */
277	/DISCARD/ : { *(.comment .note .eh_frame) }
278
279}
280