xref: /optee_os/core/arch/arm/kernel/kern.ld.S (revision f17691b3f6b27866f66636a53685bd3a6f7daa8a)
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		__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	.ARM.extab : {
120		__extab_start = .;
121		*(.ARM.extab*)
122		__extab_end = .;
123	}
124
125	.rodata : ALIGN(4) {
126		__rodata_start = .;
127		*(.gnu.linkonce.r.*)
128#ifdef CFG_WITH_PAGER
129		*(.rodata .rodata.__unpaged)
130#include <rodata_unpaged.ld.S>
131#else
132		*(.rodata .rodata.*)
133
134		/*
135		 * 8 to avoid unwanted padding between __start_ta_head_section
136		 * and the first structure in ta_head_section, in 64-bit
137		 * builds
138		 */
139		. = ALIGN(8);
140		__start_ta_head_section = . ;
141		KEEP(*(ta_head_section))
142		__stop_ta_head_section = . ;
143#endif
144		. = ALIGN(4);
145		__rodata_end = .;
146	}
147
148
149	.data : ALIGN(4) {
150		/* writable data  */
151		__data_start_rom = .;
152		/* in one segment binaries, the rom data address is on top
153		   of the ram data address */
154		__data_start = .;
155		*(.data .data.* .gnu.linkonce.d.*)
156		. = ALIGN(4);
157	}
158
159	.ctors : ALIGN(4) {
160		__ctor_list = .;
161		*(.ctors)
162		__ctor_end = .;
163	}
164	.dtors : ALIGN(4) {
165		__dtor_list = .;
166		*(.dtors)
167		__dtor_end = .;
168	}
169	.got : { *(.got.plt) *(.got) }
170	.dynamic : { *(.dynamic) }
171
172	__data_end = .;
173	/* unintialized data */
174	.bss : ALIGN(4) {
175		__bss_start = .;
176		*(.bss .bss.*)
177		*(.gnu.linkonce.b.*)
178		*(COMMON)
179		. = ALIGN(4);
180		__bss_end = .;
181	}
182
183	.heap1 (NOLOAD) : {
184		/*
185		 * We're keeping track of the padding added before the
186		 * .nozi section so we can do something useful with
187		 * this otherwise wasted memory.
188		 */
189		__heap1_start = .;
190#ifndef CFG_WITH_PAGER
191		. += HEAP_SIZE;
192#endif
193		. = ALIGN(16 * 1024);
194		__heap1_end = .;
195	}
196
197	/*
198	 * Uninitialized data that shouldn't be zero initialized at
199	 * runtime.
200	 *
201	 * L1 mmu table requires 16 KiB alignment
202	 */
203	.nozi (NOLOAD) : ALIGN(16 * 1024) {
204		KEEP(*(.nozi .nozi.*))
205	}
206
207#ifdef CFG_WITH_PAGER
208	.heap2 (NOLOAD) : {
209		__heap2_start = .;
210		/*
211		 * Reserve additional memory for heap, the total should
212		 * be at least HEAP_SIZE, but count what has already been
213		 * reserved in .heap1
214		 */
215		. += HEAP_SIZE - (__heap1_end - __heap1_start);
216		. = ALIGN(4 * 1024);
217		__heap2_end = .;
218	}
219
220	.text_init : ALIGN(4 * 1024) {
221		__text_init_start = .;
222/*
223 * Include list of sections needed for boot initialization, this list
224 * overlaps with unpaged.ld.S but since unpaged.ld.S is first all those
225 * sections will go into the unpaged area.
226 */
227#include <text_init.ld.S>
228		. = ALIGN(4);
229		__text_init_end = .;
230	}
231
232	.rodata_init : ALIGN(4) {
233		__rodata_init_start = .;
234#include <rodata_init.ld.S>
235		. = ALIGN(4);
236		__rodata_init_end = .;
237	}
238	__init_start = __text_init_start;
239	__init_end = .;
240	__init_size = __init_end - __text_init_start;
241
242	.text_pageable : ALIGN(4) {
243		__text_pageable_start = .;
244		*(.text*)
245		. = ALIGN(4);
246		__text_pageable_end = .;
247	}
248
249	.rodata_pageable : ALIGN(4) {
250		__rodata_pageable_start = .;
251		*(.rodata*)
252		. = ALIGN(4);
253		__start_ta_head_section = . ;
254		KEEP(*(ta_head_section))
255		__stop_ta_head_section = . ;
256		. = ALIGN(4 * 1024);
257		__rodata_pageable_end = .;
258	}
259
260	__pageable_part_start = __rodata_init_end;
261	__pageable_part_end = __rodata_pageable_end;
262	__pageable_start = __text_init_start;
263	__pageable_end = __pageable_part_end;
264
265	/*
266	 * Assign a safe spot to store the hashes of the pages before
267	 * heap is initialized.
268	 */
269	__tmp_hashes_start = __rodata_init_end;
270	__tmp_hashes_size = ((__pageable_end - __pageable_start) /
271				(4 * 1024)) * 32;
272	__tmp_hashes_end = __tmp_hashes_start + __tmp_hashes_size;
273
274	__init_mem_usage = __tmp_hashes_end - CFG_TEE_LOAD_ADDR;
275
276	ASSERT(CFG_TEE_LOAD_ADDR >= CFG_TEE_RAM_START,
277		"Load address before start of physical memory")
278	ASSERT(CFG_TEE_LOAD_ADDR < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
279		"Load address after end of physical memory")
280	ASSERT(__init_end < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE),
281		"OP-TEE can't fit init part into available physical memory")
282	ASSERT((CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE - __init_end) >
283		1 * 4096, "Too few free pages to initialize paging")
284
285
286#endif /*CFG_WITH_PAGER*/
287
288	_end = .;
289
290#ifndef CFG_WITH_PAGER
291	__init_size = __data_end - CFG_TEE_LOAD_ADDR;
292	__init_mem_usage = _end - CFG_TEE_LOAD_ADDR;
293#endif
294	. = CFG_TEE_RAM_START + CFG_TEE_RAM_VA_SIZE;
295	_end_of_ram = .;
296
297	/DISCARD/ : {
298		/* Strip unnecessary stuff */
299		*(.comment .note .eh_frame)
300		/* Strip meta variables */
301		*(__keep_meta_vars*)
302	}
303
304}
305