blob: 5fc0af37f9ea875ee952a14ef1ad2d3ff50ea757 [file] [log] [blame]
Imre Kis2cfb2b42021-12-15 19:15:42 +01001/* SPDX-License-Identifier: BSD-3-Clause */
2/*
3 * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
4 */
5
6#include <asm.S>
7
8#define R_AARCH64_RELATIVE 1027
9
10/**
11 * The following code is responsible for setting the initial value of the stack
12 * pointer and doing relocation on SP boot.
13 */
14FUNC __sp_entry, :
15 /* Use __stack_end linker symbol to set the load relative stack address. */
16 adrp x4, __stack_end
17 add x4, x4, :lo12:__stack_end
18 mov sp, x4
19
20 /*
21 * X4 = load address
22 * X5 = relocation table start
23 * X6 = relocation table end
24 */
25 adr x4, __sp_entry
26 adrp x5, __rela_start
27 add x5, x5, :lo12:__rela_start
28 adrp x6, __rela_end
29 add x6, x6, :lo12:__rela_end
30
31 /* Iterating through relocation entries */
32 cmp x5, x6
33 beq 2f
34
35 /*
36 * Loading relocation entry
37 * X7 = r_offset
38 * X8 = r_info
39 * X9 = r_addend
40 */
411: ldp x7, x8, [x5], #16
42 ldr x9, [x5], #8
43
44 /* Only R_AARCH64_RELATIVE type is supported */
45 cmp w8, #R_AARCH64_RELATIVE
46 bne 3f /* Error */
47
48 /*
49 * Apply relative adjustment on address
50 * *(load_address + r_offset) = load_address + r_addend
51 */
52 add x9, x9, x4
53 str x9, [x7, x4]
54
55 cmp x5, x6
56 bne 1b
57
582:
59 b _sp_entry
60
613:
62 adr X0, error_invalid_relocation
63 bl trace_puts
64 b .
65
66 .align 8
67error_invalid_relocation:
68 .asciz "Only R_AARCH64_RELATIVE type relocation is supported"
69 .align 8
70END_FUNC __sp_entry