xref: /optee_os/ldelf/start_a32.S (revision 8bbd9b374a51a1b8617796aae8a70c271543357f)
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_ARM_RELATIVE relocations in
20	 * read/write memory, leaving read-only and executeble memory
21	 * untouched.
22	 */
23	adr	r4, reloc_begin_rel
24	ldr	r5, reloc_begin_rel
25	ldr	r6, reloc_end_rel
26	add	r5, r5, r4
27	add	r6, r6, r4
28	cmp	r5, r6
29	beq	2f
30
31	adr	r4, _ldelf_start	/* Get the load offset */
32
33	/* Loop over the relocations (Elf32_Rel) and process all entries */
341:	ldmia	r5!, {r7-r8} /* r7 == r_offset, r8 = r_info */
35	and	r8, r8, #0xff
36	cmp	r8, #R_ARM_RELATIVE
37	/* We're currently only supporting R_ARM_RELATIVE relocations */
38	bne	3f
39
40	/* Update the pointer at r_offset + load_offset */
41	add	r7, r7, r4
42	ldr	r8, [r7]
43	add	r8, r8, r4
44	str	r8, [r7]
45
46	cmp	r5, r6
47	blo	1b
48
492:	bl	ldelf
50	mov	r0, #0
51	bl	utee_return
523:	mov	r0, #0
53	bl	utee_panic
54reloc_begin_rel:
55    .word __reloc_begin - reloc_begin_rel
56reloc_end_rel:
57    .word __reloc_end - reloc_end_rel
58END_FUNC _ldelf_start
59