1/* SPDX-License-Identifier: BSD-2-Clause */ 2/* 3 * Copyright (c) 2019, Linaro Limited 4 */ 5 6#include <asm.S> 7#include <elf_common.h> 8 9/* 10 * _start() - Entry of ldelf 11 * 12 * See include/ldelf.h for details on TEE Core interaction. 13 * 14 * void start(struct ldelf_arg *arg); 15 */ 16FUNC _ldelf_start , : 17 /* 18 * First ldelf needs to be relocated. The binary is compiled to 19 * contain only a minimal number of R_AARCH64_RELATIVE relocations 20 * in read/write memory, leaving read-only and executeble memory 21 * untouched. 22 */ 23 adr x4, reloc_begin_rel 24 ldr w5, reloc_begin_rel 25 ldr w6, reloc_end_rel 26 add x5, x5, x4 27 add x6, x6, x4 28 cmp x5, x6 29 beq 2f 30 31 adr x4, _ldelf_start /* Get the load offset */ 32 33 /* Loop over the relocations (Elf64_Rela) and process all entries */ 341: ldp x7, x8, [x5], #16 /* x7 = r_offset, x8 = r_info */ 35 ldr x9, [x5], #8 /* x9 = r_addend */ 36 and x8, x8, #0xffffffff 37 cmp x8, #R_AARCH64_RELATIVE 38 /* We're currently only supporting R_AARCH64_RELATIVE relocations */ 39 bne 3f 40 41 /* 42 * Update the pointer at r_offset + load_offset with r_addend + 43 * load_offset. 44 */ 45 add x7, x7, x4 46 add x9, x9, x4 47 str x9, [x7] 48 49 cmp x5, x6 50 blo 1b 51 522: bl ldelf 53 mov x0, #0 54 bl utee_return 553: mov x0, #0 56 bl utee_panic 57reloc_begin_rel: 58 .word __reloc_begin - reloc_begin_rel 59reloc_end_rel: 60 .word __reloc_end - reloc_end_rel 61END_FUNC _ldelf_start 62