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