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