11bb92983SJerome Forissier/* SPDX-License-Identifier: (BSD-2-Clause AND MIT) */ 21f09fc53SJerome Forissier/* 31f09fc53SJerome Forissier * Copyright (c) 2014, Linaro Limited 41f09fc53SJerome Forissier * All rights reserved. 51f09fc53SJerome Forissier * 61f09fc53SJerome Forissier * Redistribution and use in source and binary forms, with or without 71f09fc53SJerome Forissier * modification, are permitted provided that the following conditions are met: 81f09fc53SJerome Forissier * 91f09fc53SJerome Forissier * 1. Redistributions of source code must retain the above copyright notice, 101f09fc53SJerome Forissier * this list of conditions and the following disclaimer. 111f09fc53SJerome Forissier * 121f09fc53SJerome Forissier * 2. Redistributions in binary form must reproduce the above copyright notice, 131f09fc53SJerome Forissier * this list of conditions and the following disclaimer in the documentation 141f09fc53SJerome Forissier * and/or other materials provided with the distribution. 151f09fc53SJerome Forissier * 161f09fc53SJerome Forissier * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 171f09fc53SJerome Forissier * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 181f09fc53SJerome Forissier * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191f09fc53SJerome Forissier * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 201f09fc53SJerome Forissier * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211f09fc53SJerome Forissier * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221f09fc53SJerome Forissier * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231f09fc53SJerome Forissier * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241f09fc53SJerome Forissier * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251f09fc53SJerome Forissier * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261f09fc53SJerome Forissier * POSSIBILITY OF SUCH DAMAGE. 271f09fc53SJerome Forissier */ 281f09fc53SJerome Forissier 291f09fc53SJerome Forissier/* 301f09fc53SJerome Forissier * Copyright (c) 2008-2010 Travis Geiselbrecht 311f09fc53SJerome Forissier * 321f09fc53SJerome Forissier * Permission is hereby granted, free of charge, to any person obtaining 331f09fc53SJerome Forissier * a copy of this software and associated documentation files 341f09fc53SJerome Forissier * (the "Software"), to deal in the Software without restriction, 351f09fc53SJerome Forissier * including without limitation the rights to use, copy, modify, merge, 361f09fc53SJerome Forissier * publish, distribute, sublicense, and/or sell copies of the Software, 371f09fc53SJerome Forissier * and to permit persons to whom the Software is furnished to do so, 381f09fc53SJerome Forissier * subject to the following conditions: 391f09fc53SJerome Forissier * 401f09fc53SJerome Forissier * The above copyright notice and this permission notice shall be 411f09fc53SJerome Forissier * included in all copies or substantial portions of the Software. 421f09fc53SJerome Forissier * 431f09fc53SJerome Forissier * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 441f09fc53SJerome Forissier * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 451f09fc53SJerome Forissier * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 461f09fc53SJerome Forissier * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 471f09fc53SJerome Forissier * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 481f09fc53SJerome Forissier * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 491f09fc53SJerome Forissier * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 501f09fc53SJerome Forissier */ 511f09fc53SJerome Forissier 52a4b7d181SEtienne Carriere#include <mm/core_mmu.h> 531f09fc53SJerome Forissier#include <platform_config.h> 54a4b7d181SEtienne Carriere#include <util.h> 557dfe8f27SEtienne Carriere 566a815afaSZeng Tao/* 57f3368ec8SJerome Forissier * Note: 58f3368ec8SJerome Forissier * Clang 11 (ld.lld) generates non-relocatable reference when using ROUNDDOWN() 59f3368ec8SJerome Forissier * from <util.h>, which does not work with ASLR. 60f3368ec8SJerome Forissier */ 61f3368ec8SJerome Forissier#define LD_ROUNDDOWN(x, y) ((x) - ((x) % (y))) 62f3368ec8SJerome Forissier 637a976658SJerome ForissierOUTPUT_FORMAT(CFG_KERN_LINKER_FORMAT) 647a976658SJerome ForissierOUTPUT_ARCH(CFG_KERN_LINKER_ARCH) 651f09fc53SJerome Forissier 661f09fc53SJerome ForissierENTRY(_start) 671f09fc53SJerome ForissierSECTIONS 681f09fc53SJerome Forissier{ 69ee34e7eaSJens Wiklander . = TEE_LOAD_ADDR; 70d690c838SJens Wiklander ASSERT(!(TEE_LOAD_ADDR & (SMALL_PAGE_SIZE - 1)), 71d690c838SJens Wiklander "text start should be page aligned") 721f09fc53SJerome Forissier __text_start = .; 73eb7e2775SEtienne Carriere 74eb7e2775SEtienne Carriere /* 75ee34e7eaSJens Wiklander * Memory between TEE_LOAD_ADDR and page aligned rounded down 76eb7e2775SEtienne Carriere * value will be mapped with unpaged "text" section attributes: 77eb7e2775SEtienne Carriere * likely to be read-only/executable. 78eb7e2775SEtienne Carriere */ 79f3368ec8SJerome Forissier __flatmap_unpg_rx_start = LD_ROUNDDOWN(__text_start, SMALL_PAGE_SIZE); 800138f2a8SEtienne Carriere 817dfe8f27SEtienne Carriere .text : { 828473540dSJens Wiklander KEEP(*(.text._start)) 831385854bSJens Wiklander __identity_map_init_start = .; 84889fb568SJerome Forissier __text_data_start = .; 85889fb568SJerome Forissier *(.identity_map.data) 86889fb568SJerome Forissier __text_data_end = .; 871385854bSJens Wiklander *(.identity_map .identity_map.* \ 881385854bSJens Wiklander /* 891385854bSJens Wiklander * The one below is needed because it's a weak 901385854bSJens Wiklander * symbol that may be overridden by platform 911385854bSJens Wiklander * specific code. 921385854bSJens Wiklander */ 931385854bSJens Wiklander .text.get_core_pos_mpidr) 941385854bSJens Wiklander __identity_map_init_end = .; 958473540dSJens Wiklander KEEP(*(.text.init .text.plat_cpu_reset_early \ 968473540dSJens Wiklander .text.reset .text.reset_primary .text.unhandled_cpu \ 978473540dSJens Wiklander .text.__assert_flat_mapped_range)) 981f09fc53SJerome Forissier 991f09fc53SJerome Forissier#ifdef CFG_WITH_PAGER 1001f09fc53SJerome Forissier *(.text) 1011f09fc53SJerome Forissier/* Include list of sections needed for paging */ 1021f09fc53SJerome Forissier#include <text_unpaged.ld.S> 1031f09fc53SJerome Forissier#else 1041f09fc53SJerome Forissier *(.text .text.*) 1051f09fc53SJerome Forissier#endif 1061f09fc53SJerome Forissier *(.sram.text.glue_7* .gnu.linkonce.t.*) 107f0f7c8a6SJens Wiklander . = ALIGN(8); 1081f09fc53SJerome Forissier } 1097dfe8f27SEtienne Carriere __text_end = .; 1101f09fc53SJerome Forissier 1113181c736SEtienne Carriere#ifdef CFG_CORE_RODATA_NOEXEC 1123181c736SEtienne Carriere . = ALIGN(SMALL_PAGE_SIZE); 1133181c736SEtienne Carriere#endif 1140138f2a8SEtienne Carriere __flatmap_unpg_rx_size = . - __flatmap_unpg_rx_start; 1150138f2a8SEtienne Carriere __flatmap_unpg_ro_start = .; 1160138f2a8SEtienne Carriere 1170f4fb8caSZeng Tao .rodata : ALIGN(8) { 1180f4fb8caSZeng Tao __rodata_start = .; 1190f4fb8caSZeng Tao *(.gnu.linkonce.r.*) 1200f4fb8caSZeng Tao#ifdef CFG_WITH_PAGER 12127c64925SJens Wiklander *(.rodata .rodata.__unpaged .rodata.__unpaged.*) 1220f4fb8caSZeng Tao#include <rodata_unpaged.ld.S> 1230f4fb8caSZeng Tao#else 1240f4fb8caSZeng Tao *(.rodata .rodata.*) 125c0af48e6SJerome Forissier#ifndef CFG_CORE_ASLR 1265e4210e9SJens Wiklander . = ALIGN(8); 1275e4210e9SJens Wiklander KEEP(*(SORT(.scattered_array*))); 1280f4fb8caSZeng Tao#endif 129c0af48e6SJerome Forissier#endif 1300f4fb8caSZeng Tao . = ALIGN(8); 1310f4fb8caSZeng Tao __rodata_end = .; 1320f4fb8caSZeng Tao } 1330f4fb8caSZeng Tao 134487f8cd2SJerome Forissier#if defined(CFG_CORE_ASLR) 135487f8cd2SJerome Forissier .data.rel.ro : { 136487f8cd2SJerome Forissier#if !defined(CFG_WITH_PAGER) 137487f8cd2SJerome Forissier . = ALIGN(8); 138c0af48e6SJerome Forissier KEEP(*(SORT(.scattered_array*))); 139487f8cd2SJerome Forissier#endif 140487f8cd2SJerome Forissier *(.data.rel.ro.__unpaged .data.rel.ro.__unpaged.*) 141c0af48e6SJerome Forissier } 142c0af48e6SJerome Forissier#endif 143c0af48e6SJerome Forissier 144dbec41baSJens Wiklander .got : { *(.got.plt) *(.got) } 1457a6682fcSRuchika Gupta .note.gnu.property : { *(.note.gnu.property) } 1461f09fc53SJerome Forissier .plt : { *(.plt) } 1471f09fc53SJerome Forissier 14840c41c9cSJens Wiklander .ctors : ALIGN(8) { 14940c41c9cSJens Wiklander __ctor_list = .; 15040c41c9cSJens Wiklander KEEP(*(.ctors .ctors.* .init_array .init_array.*)) 15140c41c9cSJens Wiklander __ctor_end = .; 15240c41c9cSJens Wiklander } 15340c41c9cSJens Wiklander .dtors : ALIGN(8) { 15440c41c9cSJens Wiklander __dtor_list = .; 15540c41c9cSJens Wiklander KEEP(*(.dtors .dtors.* .fini_array .fini_array.*)) 15640c41c9cSJens Wiklander __dtor_end = .; 15740c41c9cSJens Wiklander } 15840c41c9cSJens Wiklander 1591f09fc53SJerome Forissier /* .ARM.exidx is sorted, so has to go in its own output section. */ 1609cb4152fSJens Wiklander .ARM.exidx : ALIGN(8) { 1611f09fc53SJerome Forissier __exidx_start = .; 1621f09fc53SJerome Forissier *(.ARM.exidx* .gnu.linkonce.armexidx.*) 1631f09fc53SJerome Forissier __exidx_end = .; 1641f09fc53SJerome Forissier } 1651f09fc53SJerome Forissier 1669cb4152fSJens Wiklander .ARM.extab : ALIGN(8) { 167923c1f34SJens Wiklander __extab_start = .; 168923c1f34SJens Wiklander *(.ARM.extab*) 169923c1f34SJens Wiklander __extab_end = .; 170923c1f34SJens Wiklander } 171923c1f34SJens Wiklander 17210d13b28SEtienne Carriere /* Start page aligned read-write memory */ 17310d13b28SEtienne Carriere#ifdef CFG_CORE_RWDATA_NOEXEC 17410d13b28SEtienne Carriere . = ALIGN(SMALL_PAGE_SIZE); 17510d13b28SEtienne Carriere#endif 1760138f2a8SEtienne Carriere __flatmap_unpg_ro_size = . - __flatmap_unpg_ro_start; 17715216d4dSVolodymyr Babchuk 178b76b2296SJerome Forissier#ifdef CFG_NS_VIRTUALIZATION 17915216d4dSVolodymyr Babchuk __flatmap_nex_rw_start = . ; 18015216d4dSVolodymyr Babchuk .nex_data : ALIGN(8) { 18115216d4dSVolodymyr Babchuk *(.nex_data .nex_data.*) 18215216d4dSVolodymyr Babchuk } 18315216d4dSVolodymyr Babchuk 18415216d4dSVolodymyr Babchuk .nex_bss : ALIGN(8) { 18515216d4dSVolodymyr Babchuk __nex_bss_start = .; 18615216d4dSVolodymyr Babchuk *(.nex_bss .nex_bss.*) 18715216d4dSVolodymyr Babchuk __nex_bss_end = .; 18815216d4dSVolodymyr Babchuk } 18915216d4dSVolodymyr Babchuk 19015216d4dSVolodymyr Babchuk /* 19115216d4dSVolodymyr Babchuk * We want to keep all nexus memory in one place, because 19215216d4dSVolodymyr Babchuk * it should be always mapped and it is easier to map one 19315216d4dSVolodymyr Babchuk * memory region than two. 19415216d4dSVolodymyr Babchuk * Next section are NOLOAD ones, but they are followed 19515216d4dSVolodymyr Babchuk * by sections with data. Thus, this NOLOAD section will 19615216d4dSVolodymyr Babchuk * be included in the resulting binary, filled with zeroes 19715216d4dSVolodymyr Babchuk */ 19815216d4dSVolodymyr Babchuk .nex_stack (NOLOAD) : { 19915216d4dSVolodymyr Babchuk __nozi_stack_start = .; 20015216d4dSVolodymyr Babchuk KEEP(*(.nozi_stack.stack_tmp .nozi_stack.stack_abt)) 20115216d4dSVolodymyr Babchuk . = ALIGN(8); 20215216d4dSVolodymyr Babchuk __nozi_stack_end = .; 20315216d4dSVolodymyr Babchuk } 20415216d4dSVolodymyr Babchuk 20515216d4dSVolodymyr Babchuk .nex_heap (NOLOAD) : { 20615216d4dSVolodymyr Babchuk __nex_heap_start = .; 20715216d4dSVolodymyr Babchuk . += CFG_CORE_NEX_HEAP_SIZE; 20815216d4dSVolodymyr Babchuk . = ALIGN(16 * 1024); 20915216d4dSVolodymyr Babchuk __nex_heap_end = .; 21015216d4dSVolodymyr Babchuk } 21115216d4dSVolodymyr Babchuk .nex_nozi (NOLOAD) : { 2121601a3c5SJerome Forissier ASSERT(!(ABSOLUTE(.) & (16 * 1024 - 1)), "align nozi to 16kB"); 2130d206ea0SIzik Dubnov KEEP(*(.nozi.mmu.base_table .nozi.mmu.l2)) 21415216d4dSVolodymyr Babchuk } 21515216d4dSVolodymyr Babchuk 21615216d4dSVolodymyr Babchuk . = ALIGN(SMALL_PAGE_SIZE); 21715216d4dSVolodymyr Babchuk 21815216d4dSVolodymyr Babchuk __flatmap_nex_rw_size = . - __flatmap_nex_rw_start; 21915216d4dSVolodymyr Babchuk __flatmap_nex_rw_end = .; 22015216d4dSVolodymyr Babchuk#endif 22115216d4dSVolodymyr Babchuk 2220138f2a8SEtienne Carriere __flatmap_unpg_rw_start = .; 2230138f2a8SEtienne Carriere 224f0f7c8a6SJens Wiklander .data : ALIGN(8) { 2251f09fc53SJerome Forissier /* writable data */ 2261f09fc53SJerome Forissier __data_start_rom = .; 2271f09fc53SJerome Forissier /* in one segment binaries, the rom data address is on top 2281f09fc53SJerome Forissier of the ram data address */ 2291f09fc53SJerome Forissier __data_start = .; 2301f09fc53SJerome Forissier *(.data .data.* .gnu.linkonce.d.*) 231f0f7c8a6SJens Wiklander . = ALIGN(8); 2321f09fc53SJerome Forissier } 2331f09fc53SJerome Forissier 2341f09fc53SJerome Forissier /* unintialized data */ 23511b025eaSJens Wiklander .bss : { 23611b025eaSJens Wiklander __data_end = .; 2371f09fc53SJerome Forissier __bss_start = .; 2381f09fc53SJerome Forissier *(.bss .bss.*) 2391f09fc53SJerome Forissier *(.gnu.linkonce.b.*) 2401f09fc53SJerome Forissier *(COMMON) 241f0f7c8a6SJens Wiklander . = ALIGN(8); 2421f09fc53SJerome Forissier __bss_end = .; 2431f09fc53SJerome Forissier } 2441f09fc53SJerome Forissier 2451f09fc53SJerome Forissier .heap1 (NOLOAD) : { 2461f09fc53SJerome Forissier /* 2471f09fc53SJerome Forissier * We're keeping track of the padding added before the 2481f09fc53SJerome Forissier * .nozi section so we can do something useful with 2491f09fc53SJerome Forissier * this otherwise wasted memory. 2501f09fc53SJerome Forissier */ 2511f09fc53SJerome Forissier __heap1_start = .; 2521f09fc53SJerome Forissier#ifndef CFG_WITH_PAGER 253f5f914aaSJens Wiklander . += CFG_CORE_HEAP_SIZE; 2541f09fc53SJerome Forissier#endif 255bccaa847SJerome Forissier#ifdef CFG_WITH_LPAE 256bccaa847SJerome Forissier . = ALIGN(4 * 1024); 257bccaa847SJerome Forissier#else 2581f09fc53SJerome Forissier . = ALIGN(16 * 1024); 259bccaa847SJerome Forissier#endif 2601f09fc53SJerome Forissier __heap1_end = .; 2611f09fc53SJerome Forissier } 2621f09fc53SJerome Forissier /* 2631f09fc53SJerome Forissier * Uninitialized data that shouldn't be zero initialized at 2641f09fc53SJerome Forissier * runtime. 2651f09fc53SJerome Forissier * 2661f09fc53SJerome Forissier * L1 mmu table requires 16 KiB alignment 2671f09fc53SJerome Forissier */ 2687dfe8f27SEtienne Carriere .nozi (NOLOAD) : { 2691d171f95SJens Wiklander __nozi_start = .; 2701f09fc53SJerome Forissier KEEP(*(.nozi .nozi.*)) 2711d171f95SJens Wiklander . = ALIGN(16); 2721d171f95SJens Wiklander __nozi_end = .; 27315216d4dSVolodymyr Babchuk /* 27415216d4dSVolodymyr Babchuk * If virtualization is enabled, abt and tmp stacks will placed 27515216d4dSVolodymyr Babchuk * at above .nex_stack section and thread stacks will go there 27615216d4dSVolodymyr Babchuk */ 2771d171f95SJens Wiklander __nozi_stack_start = .; 278706c2c70SSumit Garg KEEP(*(.nozi_stack .nozi_stack.*)) 2791d171f95SJens Wiklander . = ALIGN(8); 2801d171f95SJens Wiklander __nozi_stack_end = .; 2811f09fc53SJerome Forissier } 282a5ac48d6SJens Wiklander#ifndef CFG_WITH_PAGER 283a5ac48d6SJens Wiklander . = ALIGN(SMALL_PAGE_SIZE); 284a5ac48d6SJens Wiklander __flatmap_free_start = .; 285a5ac48d6SJens Wiklander __flatmap_unpg_rw_size = __flatmap_free_start - __flatmap_unpg_rw_start; 286a5ac48d6SJens Wiklander#else 2871f09fc53SJerome Forissier .heap2 (NOLOAD) : { 2881f09fc53SJerome Forissier __heap2_start = .; 2891f09fc53SJerome Forissier /* 290f5f914aaSJens Wiklander * Reserve additional memory for heap, the total should be 291f5f914aaSJens Wiklander * at least CFG_CORE_HEAP_SIZE, but count what has already 292f5f914aaSJens Wiklander * been reserved in .heap1 2931f09fc53SJerome Forissier */ 294f5f914aaSJens Wiklander . += CFG_CORE_HEAP_SIZE - (__heap1_end - __heap1_start); 2957dfe8f27SEtienne Carriere . = ALIGN(SMALL_PAGE_SIZE); 2961f09fc53SJerome Forissier __heap2_end = .; 2971f09fc53SJerome Forissier } 2981f09fc53SJerome Forissier 2990138f2a8SEtienne Carriere /* Start page aligned read-only memory */ 3000138f2a8SEtienne Carriere __flatmap_unpg_rw_size = . - __flatmap_unpg_rw_start; 3010138f2a8SEtienne Carriere 3027dfe8f27SEtienne Carriere __init_start = .; 3030138f2a8SEtienne Carriere __flatmap_init_rx_start = .; 3040138f2a8SEtienne Carriere 3050138f2a8SEtienne Carriere ASSERT(!(__flatmap_init_rx_start & (SMALL_PAGE_SIZE - 1)), 3060138f2a8SEtienne Carriere "read-write memory is not paged aligned") 3070138f2a8SEtienne Carriere 3087dfe8f27SEtienne Carriere .text_init : { 3091aae2c8eSJerome Forissier __text_init_start = .; 3101f09fc53SJerome Forissier/* 3111f09fc53SJerome Forissier * Include list of sections needed for boot initialization, this list 3121f09fc53SJerome Forissier * overlaps with unpaged.ld.S but since unpaged.ld.S is first all those 3131f09fc53SJerome Forissier * sections will go into the unpaged area. 3141f09fc53SJerome Forissier */ 3151f09fc53SJerome Forissier#include <text_init.ld.S> 3165c1c14adSJens Wiklander KEEP(*(.text.startup.*)); 3175c1c14adSJens Wiklander /* Make sure constructor functions are available during init */ 3185c1c14adSJens Wiklander KEEP(*(.text._GLOBAL__sub_*)); 319f0f7c8a6SJens Wiklander . = ALIGN(8); 3201aae2c8eSJerome Forissier __text_init_end = .; 3211f09fc53SJerome Forissier } 3221f09fc53SJerome Forissier 3233181c736SEtienne Carriere#ifdef CFG_CORE_RODATA_NOEXEC 3243181c736SEtienne Carriere . = ALIGN(SMALL_PAGE_SIZE); 3253181c736SEtienne Carriere#endif 3260138f2a8SEtienne Carriere __flatmap_init_rx_size = . - __flatmap_init_rx_start; 3270138f2a8SEtienne Carriere __flatmap_init_ro_start = .; 3280138f2a8SEtienne Carriere 3297dfe8f27SEtienne Carriere .rodata_init : { 3301aae2c8eSJerome Forissier __rodata_init_start = .; 3311f09fc53SJerome Forissier#include <rodata_init.ld.S> 332c0af48e6SJerome Forissier#ifndef CFG_CORE_ASLR 3335e4210e9SJens Wiklander . = ALIGN(8); 3345e4210e9SJens Wiklander KEEP(*(SORT(.scattered_array*))); 335c0af48e6SJerome Forissier#endif 3361aae2c8eSJerome Forissier __rodata_init_end = .; 3371f09fc53SJerome Forissier } 338c0af48e6SJerome Forissier#ifdef CFG_CORE_ASLR 339c0af48e6SJerome Forissier .data.rel.ro_init : ALIGN(8) { 340c0af48e6SJerome Forissier KEEP(*(SORT(.scattered_array*))); 341c0af48e6SJerome Forissier } 342c0af48e6SJerome Forissier#endif 343c0af48e6SJerome Forissier . = ALIGN(8); 344c0af48e6SJerome Forissier __ro_and_relro_data_init_end = .; 3457dfe8f27SEtienne Carriere 346c0af48e6SJerome Forissier __init_end = ALIGN(__ro_and_relro_data_init_end, SMALL_PAGE_SIZE); 34755c1b947SJens Wiklander __get_tee_init_end = __init_end; 3487dfe8f27SEtienne Carriere __init_size = __init_end - __init_start; 3491f09fc53SJerome Forissier 3500138f2a8SEtienne Carriere /* vcore flat map stops here. No need to page align, rodata follows. */ 3510138f2a8SEtienne Carriere __flatmap_init_ro_size = __init_end - __flatmap_init_ro_start; 3520138f2a8SEtienne Carriere 353f0f7c8a6SJens Wiklander .rodata_pageable : ALIGN(8) { 3541aae2c8eSJerome Forissier __rodata_pageable_start = .; 3551f09fc53SJerome Forissier *(.rodata*) 3561aae2c8eSJerome Forissier __rodata_pageable_end = .; 3573181c736SEtienne Carriere } 3583181c736SEtienne Carriere 3593181c736SEtienne Carriere#ifdef CFG_CORE_RODATA_NOEXEC 3603181c736SEtienne Carriere . = ALIGN(SMALL_PAGE_SIZE); 3613181c736SEtienne Carriere#endif 3623181c736SEtienne Carriere 3633181c736SEtienne Carriere .text_pageable : ALIGN(8) { 3641aae2c8eSJerome Forissier __text_pageable_start = .; 3653181c736SEtienne Carriere *(.text*) 3667dfe8f27SEtienne Carriere . = ALIGN(SMALL_PAGE_SIZE); 3671aae2c8eSJerome Forissier __text_pageable_end = .; 3681f09fc53SJerome Forissier } 3691f09fc53SJerome Forissier 3707dfe8f27SEtienne Carriere __pageable_part_end = .; 3717dfe8f27SEtienne Carriere __pageable_part_start = __init_end; 3727dfe8f27SEtienne Carriere __pageable_start = __init_start; 3731f09fc53SJerome Forissier __pageable_end = __pageable_part_end; 3741f09fc53SJerome Forissier 375f6bbec8eSEtienne Carriere ASSERT(TEE_LOAD_ADDR >= TEE_RAM_START, 3761f09fc53SJerome Forissier "Load address before start of physical memory") 377f6bbec8eSEtienne Carriere ASSERT(TEE_LOAD_ADDR < (TEE_RAM_START + TEE_RAM_PH_SIZE), 3781f09fc53SJerome Forissier "Load address after end of physical memory") 379ee34e7eaSJens Wiklander ASSERT((TEE_RAM_START + TEE_RAM_PH_SIZE - __init_end) > 380bfcdda39SJens Wiklander SMALL_PAGE_SIZE * 2 + 381bfcdda39SJens Wiklander (__pageable_end - __pageable_start) / 4096 * 32 + 382bfcdda39SJens Wiklander SIZEOF(.rel) / 2 + SIZEOF(.rela) / 3 , 383bfcdda39SJens Wiklander "Too few free pages to initialize paging") 3841f09fc53SJerome Forissier 3851f09fc53SJerome Forissier 3861f09fc53SJerome Forissier#endif /*CFG_WITH_PAGER*/ 3871f09fc53SJerome Forissier 3881d171f95SJens Wiklander#ifdef CFG_CORE_SANITIZE_KADDRESS 389*2cd578baSJens Wiklander /* 390*2cd578baSJens Wiklander * Guard against moving the location counter backwards in the assignment 391*2cd578baSJens Wiklander * below. 392*2cd578baSJens Wiklander */ 393*2cd578baSJens Wiklander ASSERT(. <= (TEE_RAM_START + (TEE_RAM_VA_SIZE * 8) / 9 - 8), 394*2cd578baSJens Wiklander "TEE_RAM_VA_SIZE is too small") 395ee34e7eaSJens Wiklander . = TEE_RAM_START + (TEE_RAM_VA_SIZE * 8) / 9 - 8; 3961d171f95SJens Wiklander . = ALIGN(8); 397*2cd578baSJens Wiklander#ifndef CFG_WITH_PAGER 398*2cd578baSJens Wiklander __flatmap_free_size = LD_ROUNDDOWN(. - __flatmap_free_start, 399*2cd578baSJens Wiklander SMALL_PAGE_SIZE); 400*2cd578baSJens Wiklander#endif 4011d171f95SJens Wiklander .asan_shadow : { 4021d171f95SJens Wiklander __asan_shadow_start = .; 403446cc62aSEtienne Carriere . += TEE_RAM_VA_SIZE / 9; 4041d171f95SJens Wiklander __asan_shadow_end = .; 405127b5e99SJens Wiklander __asan_shadow_size = __asan_shadow_end - __asan_shadow_start; 4061d171f95SJens Wiklander } 4071d171f95SJens Wiklander#endif /*CFG_CORE_SANITIZE_KADDRESS*/ 4081d171f95SJens Wiklander 40980637c4fSJens Wiklander __end = .; 4101f09fc53SJerome Forissier 4111f09fc53SJerome Forissier#ifndef CFG_WITH_PAGER 412ee34e7eaSJens Wiklander __init_size = __data_end - TEE_LOAD_ADDR; 4131f09fc53SJerome Forissier#endif 414b3615c82SZeng Tao /* 415b3615c82SZeng Tao * Guard against moving the location counter backwards in the assignment 416b3615c82SZeng Tao * below. 417b3615c82SZeng Tao */ 418ee34e7eaSJens Wiklander ASSERT(. <= (TEE_RAM_START + TEE_RAM_VA_SIZE), 419446cc62aSEtienne Carriere "TEE_RAM_VA_SIZE is too small") 420ee34e7eaSJens Wiklander . = TEE_RAM_START + TEE_RAM_VA_SIZE; 4210138f2a8SEtienne Carriere 4221f09fc53SJerome Forissier _end_of_ram = .; 4231f09fc53SJerome Forissier 4240138f2a8SEtienne Carriere#ifndef CFG_WITH_PAGER 42555c1b947SJens Wiklander __get_tee_init_end = .; 426*2cd578baSJens Wiklander#ifndef CFG_CORE_SANITIZE_KADDRESS 427a5ac48d6SJens Wiklander __flatmap_free_size = _end_of_ram - __flatmap_free_start; 4280138f2a8SEtienne Carriere#endif 429*2cd578baSJens Wiklander#endif 4300138f2a8SEtienne Carriere 4315966660cSJens Wiklander /* 4325966660cSJens Wiklander * These regions will not become a normal part of the dumped 4335966660cSJens Wiklander * binary, instead some are interpreted by the dump script and 4345966660cSJens Wiklander * converted into suitable format for OP-TEE itself to use. 4355966660cSJens Wiklander */ 4365966660cSJens Wiklander .dynamic : { *(.dynamic) } 4375966660cSJens Wiklander .hash : { *(.hash) } 4385966660cSJens Wiklander .dynsym : { *(.dynsym) } 4395966660cSJens Wiklander .dynstr : { *(.dynstr) } 4405966660cSJens Wiklander 4415966660cSJens Wiklander .rel : { 4425966660cSJens Wiklander *(.rel.*) 4435966660cSJens Wiklander } 4445966660cSJens Wiklander .rela : { 4455966660cSJens Wiklander *(.rela.*) 4465966660cSJens Wiklander } 4470d928692SJens Wiklander#if !defined(CFG_CORE_ASLR) && !defined(CFG_CORE_PHYS_RELOCATABLE) 4485966660cSJens Wiklander ASSERT(SIZEOF(.rel) == 0, "Relocation entries not expected") 4495966660cSJens Wiklander ASSERT(SIZEOF(.rela) == 0, "Relocation entries not expected") 4505966660cSJens Wiklander#endif 4515966660cSJens Wiklander 4529fa130bfSJens Wiklander /DISCARD/ : { 4531f09fc53SJerome Forissier /* Strip unnecessary stuff */ 454a4235ed9SJerome Forissier *(.comment .note .eh_frame .interp) 4559fa130bfSJens Wiklander /* Strip meta variables */ 4569fa130bfSJens Wiklander *(__keep_meta_vars*) 4579fa130bfSJens Wiklander } 4581f09fc53SJerome Forissier 4591f09fc53SJerome Forissier} 4600138f2a8SEtienne Carriere 4610138f2a8SEtienne Carriere/* Unpaged read-only memories */ 46218f4fe3dSJens Wiklander__vcore_unpg_rx_start = __flatmap_unpg_rx_start; 46318f4fe3dSJens Wiklander__vcore_unpg_ro_start = __flatmap_unpg_ro_start; 4643181c736SEtienne Carriere#ifdef CFG_CORE_RODATA_NOEXEC 46518f4fe3dSJens Wiklander__vcore_unpg_rx_size = __flatmap_unpg_rx_size; 46618f4fe3dSJens Wiklander__vcore_unpg_ro_size = __flatmap_unpg_ro_size; 4673181c736SEtienne Carriere#else 46818f4fe3dSJens Wiklander__vcore_unpg_rx_size = __flatmap_unpg_rx_size + __flatmap_unpg_ro_size; 46918f4fe3dSJens Wiklander__vcore_unpg_ro_size = 0; 4703181c736SEtienne Carriere#endif 4719ebe34b0SVolodymyr Babchuk__vcore_unpg_rx_end = __vcore_unpg_rx_start + __vcore_unpg_rx_size; 4729ebe34b0SVolodymyr Babchuk__vcore_unpg_ro_end = __vcore_unpg_ro_start + __vcore_unpg_ro_size; 4730138f2a8SEtienne Carriere 4740138f2a8SEtienne Carriere/* Unpaged read-write memory */ 47518f4fe3dSJens Wiklander__vcore_unpg_rw_start = __flatmap_unpg_rw_start; 47618f4fe3dSJens Wiklander__vcore_unpg_rw_size = __flatmap_unpg_rw_size; 4779ebe34b0SVolodymyr Babchuk__vcore_unpg_rw_end = __vcore_unpg_rw_start + __vcore_unpg_rw_size; 4780138f2a8SEtienne Carriere 479a5ac48d6SJens Wiklander#ifndef CFG_WITH_PAGER 480a5ac48d6SJens Wiklander__vcore_free_start = __flatmap_free_start; 481a5ac48d6SJens Wiklander__vcore_free_size = __flatmap_free_size; 482a5ac48d6SJens Wiklander__vcore_free_end = __flatmap_free_start + __flatmap_free_size; 483a5ac48d6SJens Wiklander#endif 484a5ac48d6SJens Wiklander 485b76b2296SJerome Forissier#ifdef CFG_NS_VIRTUALIZATION 48615216d4dSVolodymyr Babchuk/* Nexus read-write memory */ 487561a5d34SJerome Forissier__vcore_nex_rw_start = __flatmap_nex_rw_start; 488561a5d34SJerome Forissier__vcore_nex_rw_size = __flatmap_nex_rw_size; 4899ebe34b0SVolodymyr Babchuk__vcore_nex_rw_end = __vcore_nex_rw_start + __vcore_nex_rw_size; 49015216d4dSVolodymyr Babchuk#endif 49115216d4dSVolodymyr Babchuk 4920138f2a8SEtienne Carriere#ifdef CFG_WITH_PAGER 4930138f2a8SEtienne Carriere/* Paged/init read-only memories */ 49418f4fe3dSJens Wiklander__vcore_init_rx_start = __flatmap_init_rx_start; 4953181c736SEtienne Carriere#ifdef CFG_CORE_RODATA_NOEXEC 49618f4fe3dSJens Wiklander__vcore_init_rx_size = __flatmap_init_rx_size; 49799c6021fSJens Wiklander__vcore_init_ro_start = __flatmap_init_ro_start; 498d461c892SJens Wiklander__vcore_init_ro_size = __flatmap_init_ro_size; 4993181c736SEtienne Carriere#else 500d461c892SJens Wiklander__vcore_init_rx_size = __flatmap_init_rx_size + __flatmap_init_ro_size; 50199c6021fSJens Wiklander__vcore_init_ro_start = __vcore_init_rx_end; 50218f4fe3dSJens Wiklander__vcore_init_ro_size = 0; 5033181c736SEtienne Carriere#endif /* CFG_CORE_RODATA_NOEXEC */ 5049ebe34b0SVolodymyr Babchuk__vcore_init_rx_end = __vcore_init_rx_start + __vcore_init_rx_size; 5059ebe34b0SVolodymyr Babchuk__vcore_init_ro_end = __vcore_init_ro_start + __vcore_init_ro_size; 50699c6021fSJens WiklanderASSERT(__vcore_init_ro_start == __vcore_init_rx_end, 50799c6021fSJens Wiklander "__vcore_init_ro_start should follow __vcore_init_rx_end") 5080138f2a8SEtienne Carriere#endif /* CFG_WITH_PAGER */ 509127b5e99SJens Wiklander 51011a9c2baSJens Wiklander#ifdef CFG_CORE_SANITIZE_KADDRESS 51118f4fe3dSJens Wiklander__asan_map_start = (__asan_shadow_start / SMALL_PAGE_SIZE) * 51218f4fe3dSJens Wiklander SMALL_PAGE_SIZE; 51318f4fe3dSJens Wiklander__asan_map_end = ((__asan_shadow_end - 1) / SMALL_PAGE_SIZE) * 51418f4fe3dSJens Wiklander SMALL_PAGE_SIZE + SMALL_PAGE_SIZE; 51518f4fe3dSJens Wiklander__asan_map_size = __asan_map_end - __asan_map_start; 51611a9c2baSJens Wiklander#endif /*CFG_CORE_SANITIZE_KADDRESS*/ 517